predict.lmvar: Predictions for model matrices

Description Usage Arguments Details Value See Also Examples

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 β_μ and β_σ and their covariance matrix present in an 'lmvar' object.

Usage

1
2
3
4
## S3 method for class '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

Details

When X_mu = NULL, the model matrix X_μ is taken from object. Likewise, when X_sigma = NULL, X_σ 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 β_μ and β_σ in object. Columns with non-matching names are ignored. In case not all names in β_μ can be matched with a column in X_mu, a warning is given. The same is true for β_σ 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_μ and X_σ.

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 σ are larger than a minimum value (see the documentation of lmvar). However, there is no guarantee that the values of σ 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 σ.

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

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

See Also

coef.lmvar and confint for maximum likelihood estimators and confidence intervals for β_μ and β_σ.

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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)

lmvar documentation built on May 16, 2019, 5:06 p.m.