Learn R Programming

elasticIsing (version 0.2)

elasticIsing: Estimate Ising model using elastic-net and cross-validation.

Description

Uses the glmnet package for elastic-net computation and the cvTools package for cross-validation error. Use optimalGraph to select the optimal graph.

Usage

elasticIsing(data, nLambda = 100, lambda.min.ratio = 0.01, alpha = seq(0, 1, length = 10), cost = c("mspe", "rmspe", "mape", "tmspe", "rtmspe"), K = 10, and = TRUE)

Arguments

data
A binary dataset
nLambda
Number of lambda tuning parameters
lambda.min.ratio
Lambda min ratio, see details.
alpha
Vector with values of alpha to test
cost
Cost functions from the cvTools package to use.
K
The number of splits in k-fold cross-validation.
and
Should an AND-rule be used? If TRUE, both A -> B and B <- A need to be non-zero to obtain the egde A -- B. If FALSE, an OR-rule is used.

Value

An elasticIsing object, with the following elements: object, with the following elements:

Details

For each alpha, the maximum lambda is obtained from glmnet. The minimum lambda for ALL levels of alpha is lambda.min.ratio * lambda.max obtained when alpha = 1.

References

Jerome Friedman, Trevor Hastie, Robert Tibshirani (2010). Regularization Paths for Generalized Linear Models via Coordinate Descent. Journal of Statistical Software, 33(1), 1-22. URL http://www.jstatsoft.org/v33/i01/. Andreas Alfons (2012). cvTools: Cross-validation tools for regression models. R package version 0.3.2. https://CRAN.R-project.org/package=cvTools

See Also

optimalGraph, costPlots

Examples

Run this code
library("IsingSampler")

# Input:
P <- 5 # Number of nodes
nSample <- 250 # Number of samples

# Chain graph:
Graph <- matrix(0, P, P)
for (i in 1:P){
  Graph[i,i%%P+1] <- Graph[i%%P+1,i] <- 0.5
}

# Thresholds:
Thresh <- rep(0, P)

# Response options (0,1 or -1,1):
Resp <- c(0L,1L)

# Simulate with metropolis:
Data <- IsingSampler(nSample, Graph, Thresh)

## Not run: 
# # Estimate:
# Res <- elasticIsing(Data)
# 
# # Optimal graph:
# optimalGraph(Res)
# 
# # Plot result:
# plot(Res)
# 
# # Cost plots:
# costPlots(Res)
# ## End(Not run)

Run the code above in your browser using DataLab