suVARglm: Step-up estimation of lag-1 VAR network.

Usage Arguments Examples

Usage

1
suVARglm(x, family, parallel = FALSE, fit = c("chi2", "aic", "bic"), k = 2, alpha = 0.05)

Arguments

x
family
parallel
fit
k
alpha

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, family, parallel = FALSE, fit = c("chi2", "aic", 
    "bic"), k = 2, alpha = 0.05) 
{
    fit <- fit[1]
    if (missing(x)) 
        stop("'x' must be assigned")
    x <- as.matrix(x)
    Ni <- ncol(x)
    Nt <- nrow(x)
    if (missing(family)) {
        if (identical(c(0, 1), sort(unique(c(x))))) 
            family <- rep("binomial", Ni)
        else family <- rep("gaussian", Ni)
    }
    if (length(family) == 1) {
        family <- list(family)
        if (Ni > 1) 
            for (i in 2:Ni) family[[i]] <- family[[1]]
    }
    if (length(family) != Ni) 
        stop("Length of family is not equal to number of variables.")
    if (isTRUE(parallel)) {
        library("parallel")
        Res <- mclapply(seq_len(Ni), function(i) suVARglminner(x, 
            i, family, fit, k, alpha), mc.cores = getOption("mc.cores", 
            detectCores()))
    }
    else {
        Res <- lapply(seq_len(Ni), function(i) suVARglminner(x, 
            i, family, fit, k, alpha))
    }
    Out <- list(adjacency = as.matrix(do.call(cbind, lapply(Res, 
        "[[", "edges"))), graph = as.matrix(do.call(cbind, lapply(Res, 
        "[[", "estimates"))), history = lapply(Res, "[[", "history"))
    return(Out)
  }

SachaEpskamp/multivar documentation built on May 9, 2019, 12:08 p.m.