# NOT RUN {
library(hierSDR)
set.seed(123)
dat <- simulate_data(nobs = 200, nvars = 6,
x.type = "some_categorical",
sd.y = 1, model = 2)
x <- dat$x ## covariates
z <- dat$z ## factor indicators
y <- dat$y ## response
dat$beta ## true coefficients that generate the subspaces
dat$z.combinations ## what combinations of z represent different subpops
## correct structural dimensions:
dat$d.correct
## fit hier SPHD model:
# }
# NOT RUN {
hiermod <- hier.sphd(x, y, z, dat$z.combinations, d = dat$d.correct,
verbose = FALSE, maxit = 250, maxk = 8200)
## validated inf criterion for choosing dimensions (the smaller the better)
hiermod$vic
cbind(hiermod$beta[[4]], NA, dat$beta[[4]])
## angles between estimated and true subspaces for each population:
mapply(function(x,y) angle(x,y), hiermod$beta, dat$beta)
## projection difference norm between estimated and true subspaces for each population:
mapply(function(x,y) projnorm(x,y), hiermod$beta, dat$beta)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab