# Tag Info

45

What's the difference between (~1 +....) and (1 | ...) and (0 | ...) etc.? Say you have variable V1 predicted by categorical variable V2, which is treated as a random effect, and continuous variable V3, which is treated as a linear fixed effect. Using lmer syntax, simplest model (M1) is: V1 ~ (1|V2) + V3 This model will estimate: P1: A global ...

20

I'm going to describe what model each of your calls to lmer() fits and how they are different and then answer your final question about selecting random effects. Each of your three models contain fixed effects for practice, context and the interaction between the two. The random effects differ between the models. lmer(ERPindex ~ practice*context + ...

19

There is a lot of information on this topic at http://glmm.wikidot.com/faq . However, in your particular case, I would suggest using library(nlme) m1 <- lme(value~status,random=~1|experiment,data=mydata) anova(m1) because you don't need any of the stuff that lmer offers (higher speed, handling of crossed random effects, GLMMs ...). lme should give you ...

19

Update 3 (May, 2013): Another really good paper on mixed models in Psychology was released in the Journal of Memory and Language (although I do not agree with the authors conclusions on how to obtain p-values, see package afex instead). It very nicely discusses on how to specify the random effects structure. Go read it! Barr, D. J., Levy, R., Scheepers, C., ...

18

This may become clearer by writing out the model formula for each of these three models. Let $Y_{ij}$ be the observation for person $i$ in site $j$ in each model and define $A_{ij}, T_{ij}$ analogously to refer to the variables in your model. glmer(counts ~ A + T, data=data, family="Poisson") is the model $$\log \big( E(Y_{ij}) \big) = \beta_0 + \beta_1 ... 13 You can fit multilevel GLMM with a Poisson distribution (with over-dispersion) using R in multiple ways. Few R packages are: lme4, MCMCglmm, arm, etc. A good reference to see is Gelman and Hill (2007) I will give an example of doing this using rjags package in R. It is an interface between R and JAGS (like OpenBUGS or WinBUGS).$$n_{ij} \sim ...

13

The lme/lmer functions from the nlme/lme4 packages are able to deal with unbalanced designs. You should make sure that time is a numeric variable. You would also probably want to test for different types of curves as well. The code will look something like this: library(lme4) #plot data with a plot per person including a regression line for each ...

13

I will answer each of your queries in turn. Is the syntax correctly specifying the clustering and random effects? The model you've fit here is, in mathematical terms, the model $$Y_{ijk} = {\bf X}_{ijk} {\boldsymbol \beta} + \eta_{i} + \theta_{ij} + \varepsilon_{ijk}$$ where $Y_{ijk}$ is the reaction time for observation $k$ during session $j$ on ...

11

No need to leave the lme4 package to account for overdispersion; just include a random effect for observation number. The BUGS/JAGS solutions mentioned are probably overkill for you, and if they aren't, you should have the easy to fit lme4 results for comparison. data$obs_effect<-1:nrow(data) ... 11 Another approach would be to wrap the call to lmer in a function that is passed the breakpoint as a parameter, then minimize the deviance of the fitted model conditional upon the breakpoint using optimize. This maximizes the profile log likelihood for the breakpoint, and, in general (i.e., not just for this problem) if the function interior to the wrapper ... 11 If you can handle abandoning p-values (and you should), you can compute a likelihood ratio that would represent the weight of evidence for the effect of status via: #compute a model where the effect of status is estimated unrestricted_fit = lmer( formula = value ~ (1|experiment) + status , REML = F #because we want to compare models on likelihood ) ... 11 Using the given regression table, we can compute the table of expected value of the dependent variable, DV, for each combination of the two factors, which might make this more clear (Note I've used the ordinary estimates, not the MCMC estimates): $$\begin{array}{c|cc} \phantom{} & {\rm GroupA} & {\rm GroupB} \\ \hline {\rm Condition1} & ... 10 Your question(s) is a little bit "big", so I'll start with some general comments and tips. Some background reading and useful packages You should probably take a look at some of the tutorial introductions to using mixed models, I would recommend starting with Baayen et al (2008) -- Baayen is the author of languageR. Barr et al (2013) discuss some issues ... 9 The R model formula lmer(measurement ~ 1 + (1 | subject) + (1 | site), mydata) fits the model$$ Y_{ijk} = \beta_0 + \eta_{i} + \theta_{j} + \varepsilon_{ijk}$$where$Y_{ijk}$is the$k$'th measurement from subject$i$at site$j$,$\eta_{i}$is the subject$i$random effect,$\theta_{j}$is the site$j$random effect and$\varepsilon_{ijk}$is the ... 9 Your model specification is fine. The varying intercept for Ward, specified in lmer as you've done with (1 | Ward), is saying that subjects within each ward might be more similar to each other on Selfreject for reasons other than WardSize or Gender, so you are controlling for between-ward heterogeneity. You can think of the "1" as a column of 1s (i.e., a ... 9 You should note that T is none of your model's a random effects terms, but a fixed effect. Random effects are only those effects that appear after the | in a lmer formula! A more thorough discussion of what this specification does you can find in this lmer faq question. From this questions your model should give the following (for your fixed effect T): A ... 8 The issue is that the calculation of p-values for these models is not trivial, see dicussion here so the authors of the lme4 package have purposely chosen not to include p-values in the output. You may find a method of calculating these, but they will not necessarily be correct. 8 This is a highly-cited paper on mixed models for ecology and evolution: Bolker et al. (2009) Generalized linear mixed models: a practical guide for ecology and evolution Trends in Ecology & Evolution Vol. 24 pp127-135 (PDF) (from ScienceDirect with links to Supplementary Content). 8 I think the problem is with your expectations:) Note that when you added a random intercept for each individual, the standard error of the intercepts increased. Since each individual can have his/her own intercept, the group average is less certain. The same thing happened with the random slope: you are not estimating one common (within-group) slope anymore, ... 8 The lmer package's author made a conscious choice not to create p-values for the fixed effects. Some packages do, but he feels that they are doing simplistic calculations that are misleading. (Many statisticians feel that there's a p-value obsession that causes confusion in and of itself, but that's a separate matter.) He addresses the question in: this ... 8 (Italics represent corrected text) You are making a 'mistake' in your model specification given what you say you want. Random effects: Groups Name Variance Std.Dev. Corr Item (Intercept) 273.508 16.5381 Subject Gramgram 0.000 0.0000 Gramungram 3717.213 60.9689 ... 7 Not enough reputation to comment, so I'll post this as an answer. There are a number of questions like this already around. you might want to look at this message. However, (1|group1/group2) should work with all but very old versions of lme4, so if that gives you an error, there is probably something wrong with the way you set up your data. Note that once ... 7 Using maximum likelihood, any of these can be compared with AIC; if the fixed effects are the same (m1 to m4), using either REML or ML is fine, with REML usually preferred, but if they are different, only ML can be used. However, interpretation is usually difficult when both fixed effects and random effects are changing, so in practice, most recommend ... 7 There is a post on the R list by lme4's author for why p-values are not displayed. He suggests using MCMC samples instead, which you do using the pvals.fnc from the languageR package: library("lme4") library("languageR") model=lmer(...) pvals.fnc(model) See http://www2.hawaii.edu/~kdrager/MixedEffectsModels.pdf for an example and details. 7 For the definition of the rank of a matrix, you can refer to any good textbook on linear algebra, or have a look at the Wikipedia page. A$n \times p$matrix$X$is said to be full rank if$n < p$, and its columns are not a linear combination of each other . In that case, the$n \times n$matrix$X^TX$is positive definite, which implies that it has an ... 7 lmer uses Laplace approximation, when the whole normal distribution of the random effect is approximated at its mode. This approximation is known to produce the estimates of the variance components that are biased down. lme uses a more thorough approximation via Gaussian quadrature approximation, but I neither know the default number of integration points ... 7 The estimate, ID's variance = 0, indicates that the level of between-group variability is not sufficient to warrant incorporating random effects in the model; ie. your model is degenerate. As you correctly identify yourself: most probably, yes; ID as a random effect is unnecessary. Few things spring to mind to test this assumption: You could compare ... 6 I believe that the key is that you can pass in a list, so varcomp would become: varcomp <- function (data, indices, formula) { d1 <- data$d1[indices,] #sample for boot d2 <- data\$d2[indices,] #sample for boot fit1 <- lmer(formula, data=d1) #linear model fit2 <- lmer(formula, data=d2) #linear model a = (attr (VarCorr(fit1), "sc")^2) #output ...

6

The following article endeavours to promote the use of multilevel modelling in social science settings: Bliese, P. D. & Ployhart, R. E. (2002). Growth Modeling Using Random Coefficient Models: Model Building, Testing, and Illustrations, Organizational Research Methods, Vol. 5 No. 4, October 2002 362-387. PDF To quote the abstract: In this ...

Only top voted, non community-wiki answers of a minimum length are eligible