predict.ggmncv: Predict method for 'ggmncv' Objects

Description Usage Arguments Value References Examples

View source: R/predict.R

Description

There is a direct correspondence between the inverse covariance matrix and multiple regression \insertCitestephens1998,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

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

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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)

GGMncv documentation built on Dec. 15, 2021, 9:10 a.m.