[R] lme random effects in additive models with interaction
elifnurdogruoz
elifnurdogruoz at mynet.com
Thu Jun 21 08:47:48 CEST 2012
Hello,
I work with a mixed model with 4 predictor variables Time, Size, Charge,
Density and Size, Charge, Density are factors, all with two levels. Hence I
want to put their interactions with Time into the model. But, I have two
data sets (Replication 1 and 2) and I want that Replication is random
effect. Here is my code:
knots <- default.knots(Time)
z <- outer(Time, knots, "-")
z <- z * (z > 0)
z<-z^2
i.size50 <- I(Size==50)
i.chargepos <- I(Charge=="+")
i.densitylow <- I(Density==0.001)
X <- cbind( I(Time^2),Time*i.size50,Time*i.chargepos,Time*i.densitylow)
Z <- cbind( z, z*i.size50, z*i.chargepos,z*i.densitylow)
K <- length(knots)
block.ind <- list(1:K, (K+1):(2*K),(2*K+1):(3*K),(3*K+1):(4*K))
Z.block <- list()
for (i in 1:length(block.ind))
Z.block[[i]] <-
as.formula(paste("~Z[,c(",paste(block.ind[[i]],collapse=","),")]-1"))
group <- rep(1, length(Time))
model.data <- groupedData(y~X|group, data=data.frame(X, y))
fit <- lme(y~-1+X, data=model.data, random=pdBlocked(list(
pdBlocked(Z.block,pdClass="pdIdent"), pdIdent(~-1+ Replication) ))
,control=list(maxIter=1000, msMaxIter=1000, niterEM=1000))
It gives errror: "Error: getResponseFormula(el) : "Form" must be a two
sided formula"
Does anybody help how can I write random part?
Thanks..
--
View this message in context: http://r.789695.n4.nabble.com/lme-random-effects-in-additive-models-with-interaction-tp4634067.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list