Learn R Programming

GGMncv (version 2.1.1)

predict.ggmncv: Predict method for ggmncv Objects

Description

There is a direct correspondence between the inverse covariance matrix and multiple regression stephens1998,kwan2014regressionGGMncv. This readily allows for converting the off diagonal elements to regression coefficients, opening the door to out-of-sample prediction in multiple regression.

Usage

# S3 method for ggmncv
predict(object, train_data = NULL, newdata = NULL, ...)

Arguments

object

An object of class ggmncv.

train_data

Data used for model fitting (defaults to NULL).

newdata

An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

...

Currently ignored.

Value

A matrix of predicted values, of dimensions rows (in the training/test data) by the number of nodes (columns).

References

Examples

Run this code
# NOT RUN {
# data
Y <- scale(Sachs)

# test data
Ytest <- Y[1:100,]

# training data
Ytrain <- Y[101:nrow(Y),]

fit <- ggmncv(cor(Ytrain), n = nrow(Ytrain),
              progress = FALSE)

pred <- predict(fit, newdata = Ytest)

round(apply((pred - Ytest)^2, 2, mean), 2)
# }

Run the code above in your browser using DataLab