1
- # #' Make template for relative covariance factor
1
+ # #' Create a section of a transposed random effects model matrix
2
+ # #'
3
+ # #' @param grp Grouping factor for a particular random effects term.
4
+ # #' @param mm Dense model matrix for a particular random effects term.
5
+ # #' @return Section of a random effects design matrix corresponding to a
6
+ # #' particular term.
7
+ # #' @examples
8
+ # #' ## consider a term (x | g) with:
9
+ # #' ## number of observations, n = 6
10
+ # #' ## number of levels, nl = 3
11
+ # #' ## number of columns ('predictors'), nc = 2
12
+ # #' (X <- cbind("(Intercept)"=1,x=1:6)) # an intercept in the first column
13
+ # #' # and 1:6 predictor in the other
14
+ # #' (g <- as.factor(letters[rep(1:3,2)])) # grouping factor
15
+ # #' nrow(X) # n = 6
16
+ # #' nrow(X) == length(g) # and consistent n between X and g
17
+ # #' ncol(X) # nc = 2
18
+ # #' nlevels(g) # nl = 3
19
+ # #' Zsection(g, X)
20
+ mkZtSection <- function (grp ,mm ) {
21
+ Jt <- as(as.factor(grp ), Class = " sparseMatrix" )
22
+ KhatriRao(Jt ,t(mm ))
23
+ }
24
+
25
+ # #' Make transposed random-effects model matrix
26
+ mkZt <- function (grp ,mm ){
27
+ ZtSections <- mapply(mkZtSection , grp , mm )
28
+ rBind(ZtSections )
29
+ }
30
+
31
+
32
+ # #' Make a single template for a relative covariance factor
2
33
# #'
3
34
# #' @param nc Number of columns in a dense model matrix for a particular
4
35
# #' random effects term
@@ -16,7 +47,7 @@ mkTemplate <- function(nc){
16
47
sparseMatrix(i = i ,j = j ,x = theta )
17
48
}
18
49
19
- # #' Make templates for relative covariance factor
50
+ # #' Make list of templates for relative covariance factor
20
51
mkTemplates <- function (nc ) lapply(nc , mkTemplate )
21
52
22
53
# #' Make vector of indices giving the mapping from theta to Lambdat
@@ -51,3 +82,4 @@ mkTheta <- function(templates){
51
82
thetas <- lapply(templates , slot , " x" )
52
83
unlist(thetas )
53
84
}
85
+
0 commit comments