R: cant get a lme{nlme} to fit when using self-constructed interaction variables -


i'm trying lme self constructed interaction variables fit. need post-hoc analysis.

library(nlme)  # construct fake dataset obsr <- 100 dist <- rep(rnorm(36), times=obsr) meth <- dist+rnorm(length(dist), mean=0, sd=0.5); rm(dist) meth <- meth/dist(range(meth)); meth <- meth-min(meth) main <- data.frame(meth = meth,                    cpgl = as.factor(rep(1:36, times=obsr)),                    pbid = as.factor(rep(1:obsr, each=36)),                    agem = rep(rnorm(obsr, mean=30, sd=10), each=36),                    trma = as.factor(rep(sample(c(true, false), size=obsr, replace=true), each=36)),                    depr = as.factor(rep(sample(c(true, false), size=obsr, replace=true), each=36)))  # check if factor combinations present # true real dataset; naturally true fake dataset with(main, all(table(depr, trma, cpgl) >= 1))  # construct interaction variables main$depr_trma <- interaction(main$depr, main$trma, sep=":", drop=true) main$depr_cpgl <- interaction(main$depr, main$cpgl, sep=":", drop=true) main$trma_cpgl <- interaction(main$trma, main$cpgl, sep=":", drop=true) main$depr_trma_cpgl <- interaction(main$depr, main$trma, main$cpgl, sep=":", drop=true)  # model without preconstructed interaction variables form1 <- list(fixd = meth ~ agem + depr + trma + depr*trma + cpgl +                             depr*cpgl +trma*cpgl + depr*trma*cpgl,               rndm = ~ 1 | pbid,               corr = ~ cpgl | pbid)  modl1 <- nlme::lme(fixed=form1[["fixd"]],                    random=form1[["rndm"]],                    correlation=corcompsymm(form=form1[["corr"]]),                    data=main)  # model preconstructed interaction variables form2 <- list(fixd = meth ~ agem + depr + trma + depr_trma + cpgl +                             depr_cpgl + trma_cpgl + depr_trma_cpgl,               rndm = ~ 1 | pbid,               corr = ~ cpgl | pbid)  modl2 <- nlme::lme(fixed=form2[["fixd"]],                    random=form2[["rndm"]],                    correlation=corcompsymm(form=form2[["corr"]]),                    data=main) 

the first model fits without problems whereas second model gives me following error:

error in meem(object, conlin, control$niterem) :    singularity in backsolve @ level 0, block 1 

nothing found out error far helped me solve problem. solution pretty easy.

can me? in advance!


edit 1:

when run:

modl3 <- lm(form1[["fixd"]], data=main) modl4 <- lm(form2[["fixd"]], data=main) 

the summaries reveal modl4 (with self constructed interaction variables) in contrast modl3 shows many more predictors. in 4 not in 3 show na coefficients. problem therefore lies within way create interaction variables...


edit 2:

in meantime created interaction variables "by hand" (mainly paste() , grepl()) - seems work now. still interested in how have realized using interaction() function.

i should have constructed largest of interaction variables (combining 3 simple variables).

if model gets fit. likelihoods close each other , number of coefficients matches exactly.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -