Learn R Programming

lmvar (version 1.5.2)

predict.lmvar: Predictions for model matrices

Description

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

The estimators and intervals are based on the maximum likelihood-estimators for \(\beta_\mu\) and \(\beta_\sigma\) and their covariance matrix present in an 'lmvar' object.

Usage

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

Arguments

object

Object of class 'lmvar'

X_mu

Model matrix for the expected values

X_sigma

Model matrix for the logarithm of the standard deviations

mu

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

sigma

Boolean, specifies whether or not to include the 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 predict 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

When X_mu = NULL, the model matrix \(X_\mu\) is taken from object. Likewise, when X_sigma = NULL, \(X_\sigma\) is taken from object.

Both X_mu and X_sigma must have column names. Column names are matched with the names of the elements of \(\beta_\mu\) and \(\beta_\sigma\) in object. Columns with non-matching names are ignored. In case not all names in \(\beta_\mu\) can be matched with a column in X_mu, a warning is given. The same is true for \(\beta_\sigma\) and X_sigma.

X_mu can not have a column with the name "(Intercept)". This column is added by predict.lmvar in case it is present in object. Likewise, X_sigma can not have a column with the name "(Intercept_s)". It is added by predict.lmvar in case it is present in object

Both matrices must be numeric and can not contain special values like NULL, NaN, etc.

If log = FALSE, predict.lmvar returns expected values and standard deviations for the observations \(Y\) corresponding to the model matrices \(X_\mu\) and \(X_\sigma\).

If log = TRUE, predict.lmvar returns expected values and standard deviations for \(e^Y\).

The fit in object can be obtained under the constraint that the standard deviations \(\sigma\) are larger than a minimum value (see the documentation of lmvar). However, there is no guarantee that the values of \(\sigma\) given by predict, satisfy the same constraint. This depends entirely on X_sigma.

Confidence intervals are calculated under the asumption of asymptotic normality. This asumption 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\).

predict.lmvar with X_mu = NULL and X_sigma = NULL is equivalent to the function fitted.lmvar.

See Also

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

fitted.lmvar is equivalent to predict.lmvar with X_mu = NULL and X_sigma = NULL.

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")

# Create the response vector
y = attenu$accel

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

# Calculate the expected values and standard deviations of 'accel'
# for the current magnitudes and distances
predict(fit)

# Calculate the expected values and standard deviations of 'accel' for earthquakes
# with a 10% larger magnitude, at the current distances
XP = cbind(1.1 * attenu$mag, attenu$dist)
colnames(XP) = c("mag", "dist")

XP_s = cbind(1.1 * attenu$mag, 1 / attenu$dist)
colnames(XP_s) = c("mag", "dist_inv")

predict(fit, XP, XP_s)

# Calculate only the expected values
predict(fit, XP, XP_s, sigma = FALSE)

# Calculate only the standard deviations
predict(fit, XP, XP_s, mu = FALSE)

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

# Calculate the standard deviations and their 90% confidence intervals
predict(fit, XP, XP_s, mu = FALSE, interval = "confidence", level = 0.9)

# Calculate the expected values and the 90% prediction intervals of 'accel'
predict(fit, XP, XP_s, sigma = FALSE, interval = "prediction", level = 0.9)

# Change the model and fit the log of 'accel'
y = log(attenu$accel)
fit_log = lmvar(y, X, X_s)

# Calculate the expected values and standard deviations of the log of 'accel'
predict(fit_log, XP, XP_s)

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

# Calculate the expected values and standard deviations of 'accel',
# as well as their 99% confidence intervals
predict(fit_log, XP, XP_s, log = TRUE, interval = "confidence", level = 0.99)

# }

Run the code above in your browser using DataLab