Learn R Programming

lmvar (version 1.5.2)

fitted.lmvar: Fitted values for an 'lmvar' object

Description

Estimators and confidence intervals for the expected values and standard deviations of the response vector \(Y\). Prediction intervals for \(Y\). Alternatively, estimators and intervals can be for \(e^Y\).

Usage

# S3 method for lmvar
fitted(object, mu = TRUE, sigma = TRUE, log = FALSE,
  interval = c("none", "confidence", "prediction"), level = 0.95, ...)

Arguments

object

An 'lmvar' object

mu

Boolean, specifies whether or not to return estimators and intervals for the expected values

sigma

Boolean, specifies whether or not to return estimators and intervals for the standard deviations

log

Boolean, specifies whether estimators and intervals should be for \(Y\) (log = FALSE) or for \(e^Y\) (log = TRUE).

interval

Character string, specifying the type of interval. Possible values are

  • "none" No interval, this is the default

  • "confidence" Confidence intervals for the estimators

  • "prediction" Prediction intervals

level

Numeric value between 0 and 1, specifying the confidence level

...

For compatibility with fitted generic.

Value

In the case mu = FALSE and interval = "none": a numeric vector containing the estimators for the standard deviation.

In the case sigma = FALSE and interval = "none": a numeric vector containing the estimators for the expected values.

In all other cases: a matrix with one column for each requested feature and one row for each observation. The column names are

  • mu Estimators for the expected value \(\mu\)

  • sigma Estimators for the standard deviation \(\sigma\)

  • mu_lwr Lower bound of the confidence interval for \(\mu\)

  • mu_upr Upper bound of the confidence interval for \(\mu\)

  • sigma_lwr Lower bound of the confidence interval for \(\sigma\)

  • sigma_upr Upper bound of the confidence interval for \(\sigma\)

  • lwr Lower bound of the prediction interval

  • upr Upper bound of the prediction interval

Details

If log = FALSE, fitted.lmvar returns estimators and intervals for the observations \(Y\) stored in object.

If log = TRUE, fitted.lmvar returns estimators and intervals for \(e^Y\).

Confidence intervals are calculated under the assumption of asymptotic normality. This assumption holds when the number of observations is large. Intervals must be treated cautiously in case of a small number of observations. Intervals can also be unreliable if object was created with a constraint on the minimum values of the standard deviations sigma.

This function is identical to the function predict.lmvar in which the parameters X_mu and X_sigma are left unspecified.

See Also

predict.lmvar for expected values, standard deviations and intervals for model matrices different from the ones present in object.

coef.lmvar and confint for maximum likelihood estimators and confidence intervals for \(\beta_\mu\) and \(\beta_\sigma\).

Examples

Run this code
# NOT RUN {
# As example we use the dataset 'attenu' from the library 'datasets'. The dataset contains
# the response variable 'accel' and two explanatory variables 'mag'  and 'dist'.
library(datasets)

# Create the model matrix for the expected values
X = cbind(attenu$mag, attenu$dist)
colnames(X) = c("mag", "dist")

# Create the model matrix for the standard deviations.
X_s = cbind(attenu$mag, 1 / attenu$dist)
colnames(X_s) = c("mag", "dist_inv")

# Carry out the fit
y = attenu$accel
fit = lmvar(y, X, X_s)

# Calculate the expected value of each observation
fitted(fit, sigma = FALSE)

# Calculate the standard deviation of each observation
fitted(fit, mu = FALSE)

# Calculate the expected values and their 95% confidence intervals
fitted(fit, sigma = FALSE, interval = "confidence")

# Calculate the standard deviations and their 80% confidence intervals
fitted(fit, mu = FALSE, interval = "confidence", level = 0.8)

# Calculate both the expected values and the standard deviations
fitted(fit)

# Calculate the expected values, the standard deviations and their 95% confidence intervals
fitted(fit, interval = "confidence")

# Calculate the expected values and the 90% prediction intervals
fitted(fit, interval = "prediction", level = 0.9)

# Fit the log of 'accel'
y = log(attenu$accel)
fit_log = lmvar(y, X, X_s)

# Calculate both the expected values and the standard deviations of the log of 'accel'
fitted(fit_log)

# Calculate the expected values and the standard deviations of 'accel'
fitted(fit_log, log = TRUE)

# Calculate the expected values and the standard deviations of 'accel',
# as well as their 90% confidence intervals
fitted(fit_log, log = TRUE, interval = "confidence", level = 0.9)


# }

Run the code above in your browser using DataLab