### Ex 1. See the vignette "groupKernel" for an example
### inspired from computer experiments.
### Ex 2. Below an example in data analysis.
country <- c("B", "B", "B", "F", "F" ,"F", "D", "D", "D")
cities <- c("AntWerp", "Ghent" , "Charleroi", "Paris", "Marseille",
"Lyon", "Berlin", "Hamburg", "Munchen")
myGroupList <- list(B = cities[1:3],
F = cities[4:6],
D = cities[7:9])
## create a nested covariance.
# first way, with argument 'groupList':
nest1 <- covQualNested(input = "ccities",
groupList = myGroupList,
between = "Symm", within = "Diag",
compGrad = TRUE,
covBet = "corr", covWith = "corr")
# second way, with arguments 'group' and 'nestedLevels'
nest2 <- covQualNested(input = "ccities",
group = country, nestedLevels = cities,
between = "Symm", within = "Diag",
compGrad = TRUE,
covBet = "corr", covWith = "corr")
## 'show' and 'plot' method as automatically invocated
nest2
plot(nest2, type = "cor")
## check that the covariance matrices match for nest1 and nest2
max(abs(covMat(nest1) - covMat(nest2)))
## When the groups are not given in order, an error occurs!
countryBad <- c("B", "B", "F", "F", "F", "D", "D", "D", "B")
cities <- c("AntWerp", "Ghent", "Paris", "Marseille", "Lyon",
"Berlin", "Hamburg", "Munchen", "Charleroi")
nestBad <- try(covQualNested(input = "ccities",
group = countryBad, nestedLevels = cities,
between = "Symm", within = "Diag",
compGrad = TRUE,
covBet = "corr", covWith = "corr"))
Run the code above in your browser using DataLab