Last data update: 2014.03.03

R: Nodewise predictions and errors
predict.mgmR Documentation

Nodewise predictions and errors

Description

Computes predictions and error for all nodes in the graph.

Usage

## S3 method for class 'mgm'
predict(object, data, variables='all', ...)

Arguments

object

The output object of mgmfit, tv.mgmfit, var.mgm or tv_var.mgm.

data

A data matrix with the same properties as the data on which the model was fit. Note that different data can be used here to estimate the out of sample prediction error.

variables

A character vector of variable names or a numeric vector of column numbers for which the the nodewise predictions and nodewise error should be computed. The default variables='all' computes predictions and error for all variables.

...

Other prediction arguments.

Value

In the case of stationarty graphs the function returns a list, in the case of time varying graphs the function returns a list of lists with the following entries:

pred

p x n matrix of predictions, where p are the selected variables and n are the number of observations in the provided dataset.

error

A data frame with the columns: Variable, Error and ErrorType. As error we report the root mean squared error (RMSE) for continuous variables and the proportion of correct classification for categorical variables. For time-varying graphs, both types of errors are weighted by the same weights used during estimation.

Author(s)

Jonas Haslbeck <jonashaslbeck@gmail.com>

See Also

mgmfit, tv.mgmfit, var.mgm, tv_var.mgm, summary.mgm

Examples


## Not run: 

set.seed(1)
x1 <- rnorm(100)
x2 <- rnorm(100)
x3 <- rnorm(100) + 4*x1
data <- cbind(x1, x2, x3)
fitobj <- mgmfit(data, type=c('g', 'g', 'g'), lev=rep(1,3), d=1, ret.warn = FALSE)

fitobj$wadj # We get a strong dependency between x1-x3

# We compute nodewise predictions and errors
predobj <- predict.mgm(fitobj, data)

# And look at nodewise errors
predobj$error


## End(Not run)

Results