|
1 | 1 | ## File Name: designMatrices_aux2.R |
2 | | -## File Version: 9.167 |
| 2 | +## File Version: 9.201 |
3 | 3 |
|
4 | 4 |
|
5 | | -## function tam_A_matrix2 |
| 5 | +########################################################### |
| 6 | +## function .A.matrix |
6 | 7 | .A.matrix2 <- function( resp, formulaA=~ item + item*step, facets=NULL, |
7 | 8 | constraint=c("cases", "items"), progress=FALSE, |
8 | 9 | maxKi=NULL, Q=Q ) |
|
25 | 26 | } |
26 | 27 | } |
27 | 28 | #cat(" +++ v62" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1 |
28 | | - |
29 | 29 | ### Basic Information and Initializations |
30 | 30 | constraint <- match.arg(constraint) |
31 | 31 | if ( is.null(maxKi) ){ |
|
70 | 70 | expand.list[[vv]] <- paste( expand.list[[vv]] ) |
71 | 71 | } |
72 | 72 |
|
| 73 | + |
73 | 74 | # cat(" +++ v110" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1 |
74 | 75 | g2 <- g1 <- expand.grid(expand.list) |
75 | | - diffK <- ( stats::sd( maxKi) > 1e-10 ) |
| 76 | + diffK <- ( stats::sd( maxKi) > 0 ) |
76 | 77 | # diffK <- FALSE |
77 | 78 | diffK <- TRUE |
78 | 79 | # reduced combinations of items |
|
137 | 138 | } |
138 | 139 |
|
139 | 140 | A <- NULL |
140 | | - stepgroups <- unique( gsub( "(^|-)+step([[:digit:]])*", "\\1step([[:digit:]])*", |
141 | | - x=rownames(X), perl=TRUE ) ) |
| 141 | + |
| 142 | + stepgroups <- unique( gsub( "(^|-)+step([[:digit:]])*", "\\1step([[:digit:]])*", rownames(X) ) ) |
142 | 143 | X.out <- data.frame(as.matrix(X), stringsAsFactors=FALSE) |
143 | 144 | #cat(" +++ v150" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1 |
144 | 145 | if (progress){ |
|
155 | 156 | } |
156 | 157 | } |
157 | 158 | #****** |
158 | | - |
159 | | - |
160 | 159 | # collect xsi parameters to be excluded |
161 | 160 | xsi.elim.index <- xsi.elim <- NULL |
162 | 161 | ii <- 0 ; vv <- 1 |
163 | | - for( sg in stepgroups ){ |
164 | | - mm1 <- grep(paste0("(", sg, ")+$"), rownames(mm)) |
165 | | - ind2 <- grep( paste0("(", sg, ")+$"), rownames(mm)) |
166 | | - mm.sg.temp <- rbind( 0, apply( mm[ ind2,,drop=FALSE], 2, cumsum ) ) |
167 | | - if ( is.null(rownames(mm.sg.temp)) ){ |
168 | | - rownames(mm.sg.temp) <- paste0("rn", seq(0,nrow(mm.sg.temp)-1) ) |
169 | | - } |
| 162 | + for( sg in stepgroups ){ |
| 163 | +# sg <- stepgroups[2] |
| 164 | + # mm1 <- mm[ grep(sg, rownames(mm)),] |
| 165 | + mm1 <- grep(paste0("(", sg, ")+$"), rownames(mm)) |
| 166 | + # ind2 <- grep(sg, rownames(mm)) |
| 167 | + ind2 <- grep( paste0("(", sg, ")+$"), rownames(mm)) |
| 168 | +# if (length(ind2)>0){ |
| 169 | + mm.sg.temp <- rbind( 0, apply( mm[ ind2,,drop=FALSE], 2, cumsum ) ) |
| 170 | +# } |
| 171 | + if ( is.null(rownames(mm.sg.temp)) ){ |
| 172 | + rownames(mm.sg.temp) <- paste0("rn", seq(0,nrow(mm.sg.temp)-1) ) |
| 173 | + } |
170 | 174 | # substitute the following line later if ... |
171 | | - rownames(mm.sg.temp)[1] <- gsub("step([[:digit:]])*", "step0", sg, fixed=TRUE) |
172 | | - # rownames(mm.sg.temp)[1] <- gsub("step([[:digit:]])*", "step0", sg, fixed=FALSE, perl=TRUE) |
| 175 | + rownames(mm.sg.temp)[1] <- gsub("step([[:digit:]])*", "step0", sg, fixed=T) |
173 | 176 | rownames(mm.sg.temp)[-1] <- rownames(mm[ind2,,drop=FALSE]) |
174 | 177 | #**** |
175 | 178 | # set entries to zero if there are no categories in data |
|
255 | 258 | facet.design <- list( "facets"=facets, "facets.orig"=facets0, |
256 | 259 | "facet.list"=facet.list[otherFacets]) |
257 | 260 | A <- A[ ! duplicated( rownames(A) ), ] |
258 | | - |
259 | | - if ( max(apply(resp,2,max,na.rm=TRUE)) > 9 ){ |
260 | | - A <- A[order(rownames(A)),,drop=FALSE] |
261 | | - } |
| 261 | + A <- A[order(rownames(A)),,drop=FALSE] |
262 | 262 | X.out <- X.out[order(rownames(X.out)),,drop=FALSE] |
263 | 263 |
|
264 | 264 |
|
|
269 | 269 | xsi.elim <- data.frame( xsi.elim, xsi.elim.index ) |
270 | 270 | xsi.elim <- xsi.elim[ ! duplicated( xsi.elim[,2] ), ] |
271 | 271 | xsi.elim <- xsi.elim[ order( xsi.elim[,2] ), ] |
272 | | - } |
| 272 | +# A <- A[,-xsi.elim[,2] ] |
| 273 | + } |
| 274 | + |
273 | 275 |
|
274 | | - #--- clean xsi.constr |
| 276 | + #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ARb 2015-10-16 |
| 277 | + #@@@@ clean xsi.constr |
275 | 278 | xsi1 <- xsi.constr$xsi.constraints |
276 | 279 | xsi.constr$intercept_included <- FALSE |
277 | 280 | ind <- grep("(Intercept", rownames(xsi1), fixed=TRUE) |
278 | 281 | if ( length(ind) > 0 ){ |
279 | 282 | xsi1 <- xsi1[ - ind, ] |
280 | 283 | xsi.constr$xsi.constraints <- xsi1 |
281 | 284 | xsi.constr$intercept_included <- TRUE |
282 | | - } |
| 285 | + } |
283 | 286 | xsi1 <- xsi.constr$xsi.table |
284 | 287 | ind <- grep("(Intercept", paste(xsi1$parameter), fixed=TRUE) |
285 | 288 | if ( length(ind) > 0 ){ |
286 | 289 | xsi1 <- xsi1[ - ind, ] |
287 | 290 | xsi.constr$xsi.table <- xsi1 |
288 | | - } |
| 291 | + } |
| 292 | + #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
289 | 293 |
|
290 | 294 | #cat(" +++ out .A.matrix" ) ; z1 <- Sys.time() ; print(z1-z0) ; z0 <- z1 |
291 | | - res <- list( "A"=A, "X"=X.out, "otherFacets"=otherFacets, "xsi.constr"=xsi.constr, |
292 | | - "facet.design"=facet.design, "xsi.elim"=xsi.elim ) |
293 | | - return(res) |
| 295 | + return(list( "A"=A, "X"=X.out, "otherFacets"=otherFacets, "xsi.constr"=xsi.constr, |
| 296 | + "facet.design"=facet.design, "xsi.elim"=xsi.elim ) ) |
294 | 297 | } |
| 298 | +## end .A.matrix |
| 299 | +##################################################### |
295 | 300 |
|
296 | | - |
297 | | - |
298 | | -.A.matrix2 -> tam_A_matrix2 |
|
0 commit comments