Álvaro Cabana
12 de noviembre de 2018
Hasta ahora hemos visto modelos con efectos fijos.
\(ax + b\) —> efecto “fijo” (es igual para todas las observaciones)
\(\epsilon\) —> error “normal” \(\mathit{N}(0,\sigma_e)\)
psAnálisis sin efecto aleatorio
summary(lm(y~cond,data=d))##
## Call:
## lm(formula = y ~ cond, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7714 -1.2498 0.0424 1.0574 3.4602
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.2493 0.2013 -1.239 0.218
## cond 0.4391 0.2846 1.543 0.126
##
## Residual standard error: 1.559 on 118 degrees of freedom
## Multiple R-squared: 0.01977, Adjusted R-squared: 0.01146
## F-statistic: 2.38 on 1 and 118 DF, p-value: 0.1256
Análisis sin efecto aleatorio
summary(lm(y~cond,data=d))##
## Call:
## lm(formula = y ~ cond, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7714 -1.2498 0.0424 1.0574 3.4602
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.2493 0.2013 -1.239 0.218
## cond 0.4391 0.2846 1.543 0.126
##
## Residual standard error: 1.559 on 118 degrees of freedom
## Multiple R-squared: 0.01977, Adjusted R-squared: 0.01146
## F-statistic: 2.38 on 1 and 118 DF, p-value: 0.1256
Análisis con efecto aleatorio de sujeto
summary(lmer(y~cond+(1|sujeto),data=d))## Linear mixed model fit by REML t-tests use Satterthwaite approximations
## to degrees of freedom [lmerMod]
## Formula: y ~ cond + (1 | sujeto)
## Data: d
##
## REML criterion at convergence: 334.6
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.61164 -0.68649 0.03952 0.66964 2.16197
##
## Random effects:
## Groups Name Variance Std.Dev.
## sujeto (Intercept) 2.3170 1.5222
## Residual 0.8596 0.9272
## Number of obs: 120, groups: sujeto, 3
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) -0.2493 0.8869 2.0400 -0.281 0.8046
## cond 0.4391 0.1693 116.0000 2.594 0.0107 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## cond -0.095
Datos de experimento priming semántico (Emilia Flo et al., unpublished). Variabilidad entre los tiempos de reacción de los sujetos. Observaciones de un mismo sujeto más correlacionadas entre sí.
sem.p0Entonces, al ajustar por condición:
sem.p1En realidad está pasando esto:
sem.p2pan1pan.an0## Analysis of Variance Table
##
## Response: w
## Df Sum Sq Mean Sq F value Pr(>F)
## ses 3 0.2345 0.07815 2.3491 0.07146 .
## dia 1 0.6572 0.65718 19.7525 1.04e-05 ***
## ses:dia 3 0.1868 0.06227 1.8715 0.13311
## Residuals 634 21.0936 0.03327
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
pan.an1## Analysis of Variance Table of type III with Satterthwaite
## approximation for degrees of freedom
## Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
## ses 0.13822 0.04607 3 421.34 2.3382 0.07302 .
## dia 0.54045 0.54045 1 295.28 27.4273 3.105e-07 ***
## ses:dia 0.18473 0.06158 3 293.26 3.1250 0.02622 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Hay al menos dos bibliotecas para ajustar modelos lineales mixtos
lme4 (recomendada)
lmerTestlmer es el equivalente a lm pero con efectos aleatorios obligadoslm, pero se agrega la especificación del efecto aleatorio
+(1|variableAleatoria)+(efecto|variableAleatoria)Análisis con efecto aleatorio de sujeto
d.lmer=lmer(y~cond+(1|sujeto),data=d) # "cond" efecto fijo, 1|sujeto , efecto (aleatorio) de intercepto variable por sujeto
summary(d.lmer)## Linear mixed model fit by REML t-tests use Satterthwaite approximations
## to degrees of freedom [lmerMod]
## Formula: y ~ cond + (1 | sujeto)
## Data: d
##
## REML criterion at convergence: 334.6
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.61164 -0.68649 0.03952 0.66964 2.16197
##
## Random effects:
## Groups Name Variance Std.Dev.
## sujeto (Intercept) 2.3170 1.5222
## Residual 0.8596 0.9272
## Number of obs: 120, groups: sujeto, 3
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) -0.2493 0.8869 2.0400 -0.281 0.8046
## cond 0.4391 0.1693 116.0000 2.594 0.0107 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## cond -0.095
¿Por qué no ponemos un efecto fijo de sujeto?
d.lm.sujeto=lm(y~cond+sujeto,data=d) # "cond" efecto fijo, sujeto , efecto (fijo) de intercepto variable por sujeto
summary(d.lm.sujeto)##
## Call:
## lm(formula = y ~ cond + sujeto, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.41883 -0.64721 0.03536 0.62341 2.00703
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.5278 0.1693 -3.118 0.0023 **
## cond 0.4391 0.1693 2.594 0.0107 *
## sujetoS2 1.9277 0.2073 9.298 1.05e-15 ***
## sujetoS3 -1.0924 0.2073 -5.269 6.40e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9272 on 116 degrees of freedom
## Multiple R-squared: 0.6592, Adjusted R-squared: 0.6504
## F-statistic: 74.79 on 3 and 116 DF, p-value: < 2.2e-16
¿Por qué no ponemos un efecto fijo de sujeto?