Adding random subject or item slopes for a specific contrast
Hi Thierry Thank you very much for the reply, and apologies for the troubling code. I have two follow up questions: 1) Suppose IV is a three level factor. Would I still use this variable for the fixed effects, but then create a dummy variable reflecting the random slope that I want to include? I assume this works out the same as creating a pair of dummy variables to use for fixed effects, and then using one for the random slope. 2) Is it advisable to do this? I.e., to only include the slope for a single contrast. Or, is this problematic statistically. Thanks very much. Dave --- David M. Sidhu, MSc PhD Candidate Department of Psychology University of Calgary
On Nov 19, 2018, at 1:54 AM, Thierry Onkelinx <thierry.onkelinx at inbo.be<mailto:thierry.onkelinx at inbo.be>> wrote:
Dear David, I think you can solve this by creating a dummy variable which has zero's in case you are not interested in the random slope. Please note that sending HTML has ruined the code formating, making your code much harder to read. Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance thierry.onkelinx at inbo.be<mailto:thierry.onkelinx at inbo.be> Havenlaan 88 bus 73, 1000 Brussel www.inbo.be<http://www.inbo.be/> /////////////////////////////////////////////////////////////////////////////////////////// To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey /////////////////////////////////////////////////////////////////////////////////////////// [https://inbo-website-prd-532750756126.s3-eu-west-1.amazonaws.com/inbologoleeuw_nl.png]<https://www.inbo.be/> Op do 8 nov. 2018 om 16:55 schreef David Sidhu <dsidhu at ucalgary.ca<mailto:dsidhu at ucalgary.ca>>: Hi There I have been following the approach described in Bates et al. (2018) to simplify my random effects structure. I will use the data pasted below as an example (though the effects I describe aren?t present there, I use it only to have an example to refer to). Now, if it seems that there is variance in the random subject slope comparing IV1 level 2 vs. IV1 level 1, but in no other contrast?s random subject slope, I would like to only include a random subject slope for that one specific contrast. Also assume that the method described by Bates et al. (2018) suggests that the random effects structure should only have one component. Two questions: Is it sensible to only include this one slope? Is it possible in lme4 to only include this one slope? Thanks! Dave Subj <- rep(1:10, each = 10) Item <- rep(1:10, times = 10) IV1 <- rep(1:5, times = 20) DV <- rnorm(100) library(data.table) data <- as.data.table(cbind(Subj, Item, IV1, DV)) data$Subj <- as.factor(data$Subj) data$Item <- as.factor(data$Item) data$IV1 <- as.factor(data$IV1) library(MASS) contrasts(data$IV1) <- contr.sdif(5) library(lme4) m <- lmer(DV ~ IV1 + (1 + IV1|Subj) + (1|Item), data = data) --- David M. Sidhu, MSc PhD Candidate Department of Psychology University of Calgary _______________________________________________ R-sig-mixed-models at r-project.org<mailto:R-sig-mixed-models at r-project.org> mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models