covQualNested {kergp} | R Documentation |
Nested Qualitative Covariance
Description
Nested Qualitative Covariance
Usage
covQualNested(input = "x",
groupList = NULL,
group = NULL,
nestedLevels = NULL,
between = "Symm",
within = "Diag",
covBet = c("corr", "homo", "hete"),
covWith = c("corr", "homo", "hete"),
compGrad = TRUE,
contrasts = contr.helmod,
intAsChar = TRUE)
Arguments
input |
Name of the input, i.e. name of the column in the
data frame when the covariance kernel is evaluated with the
|
groupList |
A list giving the groups, see Examples. Groups of size 1 are accepted. Note that the group values should be given in some order, with no gap between repeated values, see Examples. |
group |
Inactive if |
nestedLevels |
Inactive if |
between |
Character giving the type of structure to use for the between
part. For now this can be one of the three choices |
within |
Character vector giving the type of structure to use for the
within part. The choices are the same as for
|
covBet , covWith |
Character vector indicating the type of covariance matrix to be used
for the generator between- or within- matrices,
as in |
compGrad |
Logical. |
contrasts |
Object of class |
intAsChar |
Logical. If |
Value
An object with class "covQualNested"
.
Caution
When covBet
and covWith
are zero, the resulting matrix
is not a correlation matrix, due to the mode of
construction. The "between" covariance matrix is a correlation but
diagonal blocks are added to the extended matrix obtained by re-sizing
the "between" covariance into a n \times n
matrix.
Note
For now the replacement method such as 'coef<-'
are inherited
from the class covQuall
. Consequently when these methods are
used they do not update the covariance structure in the between
slot nor those in the within
(list) slot.
This covariance kernel involves two
categorical (i.e. factor)
inputs, but these are nested. It could be aliased in the future as
q1Nested
or q2Nested
.
Examples
### 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"))