predict.cglasso: Predict Method for cglasso and cggm Fits

View source: R/cglasso_S3methods.R

predictR Documentation

Predict Method for cglasso and cggm Fits

Description

Obtains predictions from an R object inheriting class ‘cglasso’.

Usage

## S3 method for class 'cglasso'
predict(object, type = c("B", "mu", "Sigma", "Theta"), X.new, lambda.new, rho.new,
        ...)
        
## S3 method for class 'cggm'
predict(object, X.new, ...)

Arguments

object

an R object inheriting class ‘cglasso’, that is, the output of the model-fitting function ‘cglasso’ or ‘cggm’.

type

a description of prediction required.

X.new

matrix of new values for X at which predictions are to be made. This argument is used only if ‘type = "mu"’.

lambda.new

value of the tuning parameter lambda at which predictions are required.

rho.new

value of the tuning parameter rho at which predictions are required.

...

further arguments passed to or from other methods.

Details

If object has S3 class ‘cglasso’, then for a new pair of the tuning parameters lambda and rho, the predict function can be used to predict the estimate of the regression coefficient matrix (‘type = "B"’), the estimate of the covariance matrix (‘type = "Sigma"’) or the estimate of the precision matrix (‘type = "Theta"’). If X.new is missing and ‘type = "mu"’, then the predict function returns the predicted values using the matrix of predictors X, otherwise the predicted fitted values are computed using the matrix X.new.

For a new pair of the tuning parameters lambda and rho, the predicted values are computed using a bilinear interpolation.

If the object has S3 class ‘cggm’, then the predict function returns only the predicted fitted values using the argument X.new.

Value

The matrix of predicted values.

Author(s)

Luigi Augugliaro (luigi.augugliaro@unipa.it)

See Also

Model-fitting function cglasso and the other accessor functions coef.cglasso, fitted.cglasso, residuals.cglasso and impute.

Examples

set.seed(123)
# Y ~ N(0, Sigma) and probability of left/right censored values equal to 0.05
n <- 100L
p <- 3L
rho <- 0.3
Sigma <- outer(1L:p, 1L:p, function(i, j) rho^abs(i - j))
Z <- rcggm(n = n, Sigma = Sigma, probl = 0.05, probr = 0.05)

out <- cglasso(. ~ ., data = Z)
rho.new <- mean(out$rho)
Theta.pred <- predict(out, rho.new = rho.new, type = "Theta")
Theta.pred

# Y ~ N(b0 + XB, Sigma)  and probability of left/right censored values equal to 0.05
n <- 100L
p <- 3L
q <- 2
b0 <- runif(p)
B <- matrix(runif(q * p), nrow = q, ncol = p)
X <- matrix(rnorm(n * q), nrow = n, ncol = q)
rho <- 0.3
Sigma <- outer(1L:p, 1L:p, function(i, j) rho^abs(i - j))
Z <- rcggm(n = n, b0 = b0, X = X, B = B, Sigma = Sigma, probl = 0.05, probr = 0.05)

out <- cglasso(. ~ ., data = Z)
rho.new <- mean(out$rho)
lambda.new <- mean(out$lambda)
Theta.pred <- predict(out, lambda.new = lambda.new, rho.new = rho.new, type = "Theta")
Theta.pred

cglasso documentation built on Jan. 17, 2023, 5:10 p.m.