if (FALSE) {
## A) bwSelect for tvmgm()
# A.1) Generate noise data set
p <- 5
n <- 100
data_n <- matrix(rnorm(p*n), nrow=100)
head(data_n)
type <- c("c", "c", rep("g", 3))
level <- c(2, 2, 1, 1, 1)
x1 <- data_n[,1]
x2 <- data_n[,2]
data_n[x1>0,1] <- 1
data_n[x1<0,1] <- 0
data_n[x2>0,2] <- 1
data_n[x2<0,2] <- 0
head(data_n)
# A.2) Estimate optimal bandwidth parameter
bwobj_mgm <- bwSelect(data = data_n,
type = type,
level = level,
bwSeq = seq(0.05, 1, length=3),
bwFolds = 1,
bwFoldsize = 3,
modeltype = "mgm",
k = 3,
pbar = TRUE,
overparameterize = TRUE)
print.mgm(bwobj_mgm)
## B) bwSelect for tvmVar()
# B.1) Generate noise data set
p <- 5
n <- 100
data_n <- matrix(rnorm(p*n), nrow=100)
head(data_n)
type <- c("c", "c", rep("g", 3))
level <- c(2, 2, 1, 1, 1)
x1 <- data_n[,1]
x2 <- data_n[,2]
data_n[x1>0,1] <- 1
data_n[x1<0,1] <- 0
data_n[x2>0,2] <- 1
data_n[x2<0,2] <- 0
head(data_n)
# B.2) Estimate optimal bandwidth parameter
bwobj_mvar <- bwSelect(data = data_n,
type = type,
level = level,
bwSeq = seq(0.05, 1, length=3),
bwFolds = 1,
bwFoldsize = 3,
modeltype = "mvar",
lags = 1:3,
pbar = TRUE,
overparameterize = TRUE)
print.mgm(bwobj_mvar)
# For more examples see https://github.com/jmbh/mgmDocumentation
}
Run the code above in your browser using DataLab