Estimado Javier Villacampa Conzález
Copie parte del código que ested envió para ver que pasa en mi
computadora, solo modifique el if(try ... al principio y lógicamene al
final, llame las librerías y lo corrí, copio o pego tal cuál la salida
con algunos errores, no preste atención al porqué, entiendo que el
código debería estar bien y el problema es con la versión de R.
En mi computadora paso lo siguiente:
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R es un software libre y viene sin GARANTIA ALGUNA.
Usted puede redistribuirlo bajo ciertas circunstancias.
Escriba 'license()' o 'licence()' para detalles de distribucion.
R es un proyecto colaborativo con muchos contribuyentes.
Escriba 'contributors()' para obtener más información y
'citation()' para saber cómo citar R o paquetes de R en publicaciones.
Escriba 'demo()' para demostraciones, 'help()' para el sistema
on-line
de ayuda,
o 'help.start()' para abrir el sistema de ayuda HTML con su navegador.
Escriba 'q()' para salir de R.
> version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 0.2
year 2013
month 09
day 25
svn rev 63987
language R
version.string R version 3.0.2 (2013-09-25)
nickname Frisbee Sailing
> library(lme4)
Loading required package: lattice
Loading required package: Matrix
> require(LCFdata)
Loading required package: LCFdata
> library(LMERConvenienceFunctions)
>
> data(eeg)
> # restrict to electrode Fz and 80--180 ms window
> eeg <- eeg[eeg$Time >= 80 & eeg$Time <= 180, ]
> eeg <- eeg[, c("Subject", "Item",
"Time", "Fz",
+ "FreqB", "LengthB", "WMC")]
> # mean center FreqB
> eeg$FreqBc <- eeg$FreqB - mean(eeg$FreqB)
> # split FreqBc into 3 categories. Doesn't make sense,
> # but it's merely for example
> eeg$FreqBdc <- "high"
> eeg$FreqBdc[eeg$FreqBc<=quantile(eeg$FreqBc)[3]] <-
"mid"
> eeg$FreqBdc[eeg$FreqBc<=quantile(eeg$FreqBc)[2]] <-
"low"
> eeg$FreqBdc <- as.factor(eeg$FreqBdc)
> eeg$FreqBdc <- relevel(eeg$FreqBdc, "low")
> # mean center LengthB
> eeg$LengthBc <- eeg$LengthB - mean(eeg$LengthB)
> # mean center WMC
> eeg$WMCc <- eeg$WMC - mean(eeg$WMC)
> ### demonstrate plotDensity3d,fnc
> plotDensity3d.fnc(x = sort(unique(eeg$WMCc)),
+ y = sort(unique(eeg$LengthBc)))
> ### demonstrate plotDensity3d,fnc
> plotRaw3d.fnc(data = eeg, response = "Fz", pred =
"WMCc",
+ intr = "LengthBc", plot.type = "persp",
theta = 150)
> ### Analyze data
> # fit initial model
> m0 <- lmer(Fz ~ (FreqBdc + LengthBc + WMCc)^2 + (1 | Subject),
+ data = eeg)
Aviso en rankMatrix(X) :
rankMatrix(<large sparse Matrix>, method = 'tolNorm2') coerces
to
dense matrix.
Probably should rather use method = 'qrLINPACK' !?
> m1 <- lmer(Fz ~ (FreqBdc + LengthBc + WMCc)^2 + (1 | Subject) +
+ (1 | Item), data = eeg)
Aviso en rankMatrix(X) :
rankMatrix(<large sparse Matrix>, method = 'tolNorm2') coerces
to
dense matrix.
Probably should rather use method = 'qrLINPACK' !?
> # which model to choose?
> relLik(m0, m1)
AIC(x) AIC(y) diff relLik
3.820644e+05 3.816235e+05 4.408375e+02 5.329033e+95
> # choose m1
> # check model assumptions
> mcp.fnc(m1)
Error en match.arg(type) :
'arg' should be one of "working", "response",
"deviance", "pearson",
"partial"
> # remove outliers
> eeg <- romr.fnc(m1, eeg, trim = 2.5)
n.removed = 972
percent.removed = 1.755146
> eeg$n.removed
[1] 972
> eeg$percent.removed
[1] 1.755146
> eeg<-eeg$data
> # update model
> m1 <- lmer(Fz ~ (FreqBdc + LengthBc + WMCc)^2 + (1 | Subject) +
+ (1 | Item), data = eeg)
Aviso en rankMatrix(X) :
rankMatrix(<large sparse Matrix>, method = 'tolNorm2') coerces
to
dense matrix.
Probably should rather use method = 'qrLINPACK' !?
> # re-check model assumptions
> mcp.fnc(m1)
Error en match.arg(type) :
'arg' should be one of "working", "response",
"deviance", "pearson",
"partial"
> # forward-fit random effect structure (simple for the purposes
> # of the example).
> m2 <- ffRanefLMER.fnc(model = m1, data = eeg, ran.effects +
c("(0 + LengthBc | Subject)", "(0 + WMCc |
Item)"),
+ log.file = FALSE)
evaluating addition of (0+LengthBc|Subject) to model
log-likelihood ratio test p-value = 0.7470898
not adding (0+LengthBc|Subject) to model
evaluating addition of (0+WMCc|Item) to model
log-likelihood ratio test p-value = 5.827713e-78
adding (0+WMCc|Item) to model
> # backfit model m2. In this case, could use bfFixefLMER_t.fnc instead.
> m3 <- bfFixefLMER_F.fnc(m2, log.file = FALSE)
Error en qr(model@X) :
error in evaluating the argument 'x' in selecting a method for
function 'qr': Error: no hay un slot de nombre "X" para ese
objeto de
clase "lmerMod"
> # The calls to ffRanefLMER.fnc and bfFixefLMER_F.fnc could
> # be replaced by a call to fitLMER.fnc. In this latter case, however,
> # bfFixefLMER_F.fnc would be called first, then the random effect
> # structure would be forward fitted, and finally teh fixed effects
> # would be backfitted again.
> m3b <- fitLMER.fnc(model = m1, ran.effects = c("(0 + LengthBc |
Subject)",
+ "(0 + WMCc |
Item)"),
+ backfit.on = "F", log.file = FALSE)
========================================================
backfitting fixed effects
=======================================================Error en qr(model@X) :
error in evaluating the argument 'x' in selecting a method for
function 'qr': Error: no hay un slot de nombre "X" para ese
objeto de
clase "lmerMod"
> pamer.fnc(m3b)
Error en anova(model) : objeto 'm3b' no encontrado
> # The results are the same. This may not necessarily be the case
> # elsewhere. First forward fitting the random effect structure and
> # then backfitting the fixed effects, potentially pruning irrelevant
> # random effects, is probably the best approach. Nonetheless, there is
> # no hard evidence to this effect.
> # check model assumptions
> mcp.fnc(m3)
Error en mcp.fnc(m3) : objeto 'm3' no encontrado
> # check significance of model terms
> pamer.fnc(m3)
Error en anova(model) : objeto 'm3' no encontrado
> # Only the intercept is significant. For purposes of the
> # example, let's perform a posthoc analysis on FreqBdc on
> # model m2.
> m2.ph <-
+ mcposthoc.fnc(model = m2, var = list(ph1 = "FreqBdc"))
processing job "FreqBdchigh" (1 of 3) ...
Aviso en rankMatrix(X) :
rankMatrix(<large sparse Matrix>, method = 'tolNorm2') coerces
to
dense matrix.
Probably should rather use method = 'qrLINPACK' !?
Error en my.update(model = model, ph.list.element = x, verbosity =
verbosity) :
tentativa de obtener un slot "coefs" de un objeto cuya clase
("summary.merMod") que no es un objecto clase S4
> if(try(require(languageR,quietly=TRUE))){
+ # Generate plot for Length X Freq with function plotLMER.fnc
+ require(languageR)
+ plotLMER.fnc(m2, pred = "LengthBc", intr =
list("FreqBdc",
+
+ levels(eeg$FreqBdc), "beg", list(1 : 3, 1 : 3)))
+ }
Error en plotLMER.fnc(m2, pred = "LengthBc", intr =
list("FreqBdc",
levels(eeg$FreqBdc), :
argument should be a mer model object
> # effect of Length at each FreqB bin
> summary(object = m2.ph, term = "LengthBc")
Error en summary(object = m2.ph, term = "LengthBc") :
error in evaluating the argument 'object' in selecting a method for
function 'summary': Error: objeto 'm2.ph' no encontrado
> # Length effect different Freq bins? Start with low
> # versus mid and high
> smry <- summary(object = m2.ph, term =
"FreqBdclow:LengthBc")
Error en summary(object = m2.ph, term = "FreqBdclow:LengthBc") :
error in evaluating the argument 'object' in selecting a method for
function 'summary': Error: objeto 'm2.ph' no encontrado
> # mid versus low and high
> smry <- summary(object = m2.ph, term =
"FreqBdcmid:LengthBc")
Error en summary(object = m2.ph, term = "FreqBdcmid:LengthBc") :
error in evaluating the argument 'object' in selecting a method for
function 'summary': Error: objeto 'm2.ph' no encontrado
>
Javier Marcuzzi
El 17/10/2013 04:09 p.m., Javier Villacampa González
escribió:> if(try(require(LCFdata,quietly=TRUE))){
> ### Load and format data
> require(LCFdata)
> data(eeg)
> # restrict to electrode Fz and 80--180 ms window
> eeg <- eeg[eeg$Time >= 80 & eeg$Time <= 180, ]
> eeg <- eeg[, c("Subject", "Item",
"Time", "Fz",
> "FreqB", "LengthB", "WMC")]
> # mean center FreqB
> eeg$FreqBc <- eeg$FreqB - mean(eeg$FreqB)
> # split FreqBc into 3 categories. Doesn't make sense,
> # but it's merely for example
> eeg$FreqBdc <- "high"
> eeg$FreqBdc[eeg$FreqBc<=quantile(eeg$FreqBc)[3]] <-
"mid"
> eeg$FreqBdc[eeg$FreqBc<=quantile(eeg$FreqBc)[2]] <-
"low"
> eeg$FreqBdc <- as.factor(eeg$FreqBdc)
> eeg$FreqBdc <- relevel(eeg$FreqBdc, "low")
> # mean center LengthB
> eeg$LengthBc <- eeg$LengthB - mean(eeg$LengthB)
> # mean center WMC
> eeg$WMCc <- eeg$WMC - mean(eeg$WMC)
> ### demonstrate plotDensity3d,fnc
> plotDensity3d.fnc(x = sort(unique(eeg$WMCc)),
> y = sort(unique(eeg$LengthBc)))
> ### demonstrate plotDensity3d,fnc
> plotRaw3d.fnc(data = eeg, response = "Fz", pred =
"WMCc",
> intr = "LengthBc", plot.type =
"persp", theta = 150)
> ### Analyze data
> # fit initial model
> m0 <- lmer(Fz ~ (FreqBdc + LengthBc + WMCc)^2 + (1 | Subject),
> data = eeg)
> m1 <- lmer(Fz ~ (FreqBdc + LengthBc + WMCc)^2 + (1 | Subject) +
> (1 | Item), data = eeg)
> # which model to choose?
> relLik(m0, m1)
> # choose m1
> # check model assumptions
> mcp.fnc(m1)
> # remove outliers
> eeg <- romr.fnc(m1, eeg, trim = 2.5)
> eeg$n.removed
> eeg$percent.removed
> eeg<-eeg$data
> # update model
> m1 <- lmer(Fz ~ (FreqBdc + LengthBc + WMCc)^2 + (1 | Subject) +
> (1 | Item), data = eeg)
> # re-check model assumptions
> mcp.fnc(m1)
> # forward-fit random effect structure (simple for the purposes
> # of the example).
> m2 <- ffRanefLMER.fnc(model = m1, data = eeg, ran.effects >
c("(0 + LengthBc | Subject)", "(0 + WMCc | Item)"),
> log.file = FALSE)
> # backfit model m2. In this case, could use bfFixefLMER_t.fnc instead.
> m3 <- bfFixefLMER_F.fnc(m2, log.file = FALSE)
> # The calls to ffRanefLMER.fnc and bfFixefLMER_F.fnc could
> # be replaced by a call to fitLMER.fnc. In this latter case, however,
> # bfFixefLMER_F.fnc would be called first, then the random effect
> # structure would be forward fitted, and finally teh fixed effects
> # would be backfitted again.
> m3b <- fitLMER.fnc(model = m1, ran.effects = c("(0 + LengthBc |
Subject)",
> "(0 + WMCc |
Item)"),
> backfit.on = "F", log.file = FALSE)
> pamer.fnc(m3b)
> # The results are the same. This may not necessarily be the case
> # elsewhere. First forward fitting the random effect structure and
> # then backfitting the fixed effects, potentially pruning irrelevant
> # random effects, is probably the best approach. Nonetheless, there is
> # no hard evidence to this effect.
> # check model assumptions
> mcp.fnc(m3)
> # check significance of model terms
> pamer.fnc(m3)
> # Only the intercept is significant. For purposes of the
> # example, let's perform a posthoc analysis on FreqBdc on
> # model m2.
> m2.ph <-
> mcposthoc.fnc(model = m2, var = list(ph1 = "FreqBdc"))
> if(try(require(languageR,quietly=TRUE))){
> # Generate plot for Length X Freq with function plotLMER.fnc
> require(languageR)
> plotLMER.fnc(m2, pred = "LengthBc", intr =
list("FreqBdc",
>
> levels(eeg$FreqBdc), "beg", list(1 : 3, 1 : 3)))
> }
> # effect of Length at each FreqB bin
> summary(object = m2.ph, term = "LengthBc")
> # Length effect different Freq bins? Start with low
> # versus mid and high
> smry <- summary(object = m2.ph, term =
"FreqBdclow:LengthBc")
> # mid versus low and high
> smry <- summary(object = m2.ph, term =
"FreqBdcmid:LengthBc")
> }
> ## End(Not run)
[[alternative HTML version deleted]]