mixed-models

Contrast between variables in glmmTMB

核能气质少年 提交于 2020-06-28 03:49:08
问题 As a reproducible example, let's use the next no-sense example: > library(glmmTMB) > summary(glmmTMB(am ~ disp + hp + (1|carb), data = mtcars)) Family: gaussian ( identity ) Formula: am ~ disp + hp + (1 | carb) Data: mtcars AIC BIC logLik deviance df.resid 34.1 41.5 -12.1 24.1 27 Random effects: Conditional model: Groups Name Variance Std.Dev. carb (Intercept) 2.011e-11 4.485e-06 Residual 1.244e-01 3.528e-01 Number of obs: 32, groups: carb, 6 Dispersion estimate for gaussian family (sigma^2):

mixed-models with two random effects - statsmodels

别等时光非礼了梦想. 提交于 2020-06-13 06:31:58
问题 import pandas as pd import statsmodels.formula.api as smf df = pd.read_csv('http://www.bodowinter.com/tutorial/politeness_data.csv') df = df.drop(38) In R I would do: lmer(frequency ~ attitude + (1|subject) + (1|scenario), data=df) which in R gives me: Random effects: Groups Name Variance Std.Dev. scenario (Intercept) 219 14.80 subject (Intercept) 4015 63.36 Residual 646 25.42 Fixed effects: Estimate Std. Error t value (Intercept) 202.588 26.754 7.572 attitudepol -19.695 5.585 -3.527 I tried

Restart mixed effect model estimation with previously estimated values

五迷三道 提交于 2020-06-09 11:38:06
问题 I'm using lmer() in package lme4 to estimate mixed effects models. This works well, but now I want to run the estimation process for a fixed number of iterations, then resume the process by specifying start values, as calculated by the last estimation process. According to the help for ?lmer this is possible, by setting the arguments: start - these are the new start values, and according to the help one can extract the value in slot ST from a fitted model and use these, i.e. use x@ST maxiter

syntax for nested random effects using gamm or lme in R

梦想的初衷 提交于 2020-05-29 09:58:05
问题 I would like to fit three random effects to a gamm in R, including one that is nested in another. For independent random effects, the gamm function in the mgcv package allows specification of the random effects using the list syntax from lme , i.e: model<- gamm(y~s(x), random = list(ran1=~1,ran2=~1), data=data) This works fine. However, I would like to have 'ran2' nested inside a third variable, 'ran3'. I can't seem to find any examples, for either gamm or lme that show how to nest random

package emmeans in R not returning effect sizes

空扰寡人 提交于 2020-05-28 06:12:14
问题 I'm following this tutorial as well as ?eff_size from package emmeans to compute eff_size() for my regression model below. But I get the error: need an object with call component from the eff_size() call. Am I missing something? library(lme4) library(emmeans) h <- read.csv('https://raw.githubusercontent.com/hkil/m/master/h.csv') h$year <- as.factor(h$year) m <- lmer(scale~year*group + (1|stid), data = h) ems <- emmeans(m, pairwise ~ group*year, infer = c(T, T)) eff_size(ems, sigma = sigma(m),

Simple slopes test for merMod object with R package interactions (jtools)

一曲冷凌霜 提交于 2020-02-25 08:22:06
问题 I'm trying to conduct a simple slopes analysis for a mixed effects model obtained with lmer . The model is similar to the following: data(Orthodont,package="nlme") mod <- lme4::lmer(distance ~ age*Sex + (1|Subject), data=Orthodont) When trying to conduct a simple slopes analysis with the function sim_slopes in the package interactions , I obtain the following error message. interactions::sim_slopes(model=mod, pred=age, modx=Sex) Error: One of the requested columns does not exist. Backtrace: 1

Effects of Education Spending on Crime, multi-level mixed-model structure

不问归期 提交于 2020-02-07 04:04:49
问题 I’m looking at the effect of education_expenditure per school district on crime rate within the cities and towns those school districts serve over a fifteen year period. (The DV has 1,676,191 observations of city/town crime data over those fifteen years). Cities are technically crossed with school district, in that one city might attend multiple school districts. This means that one city could have multiple values for expenditure per student. School districts, however, overlap with counties.

R: Covariance matrix for the random effect in mixed effects model

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-24 22:57:45
问题 According to this post, matrix Omega and sigma are in the results of lmer when we fitting the mixed effect model. And here is my result. Random effects: Groups Name Variance Std.Dev. Corr subject X21 8.558e+00 2.925380 X22 2.117e-03 0.046011 -1.00 X23 2.532e-05 0.005032 1.00 -1.00 Residual 1.453e+00 1.205402 Number of obs: 100, groups: subject, 20 Since my Omega is a 3x3 diagonal matrix, so the three numbers in the Variance should be the elements in the diagonal of Omega and the number on the

How to cope with a singular fit in a linear mixed model (lme4)?

邮差的信 提交于 2020-01-23 03:05:46
问题 I am running several linear mixed models for an study about birds with the variable nest as a random variable. The thing is that in some of these models I get what is called 'singular fit': my nest random variable has a variance and st error of 0.00. Some background: I am working with wild birds to see the effect of living in noisy environments on some oxidative stress parameters. For this, we took a blood sample for each of the nestlings of each nest to do the laboratory stuff. Because of

how to allow for factor-specific variance of random effect in lme

吃可爱长大的小学妹 提交于 2020-01-21 05:06:24
问题 I assume that the random effects variances in my mixed effect model will be different for different levels of the fixed factor BTyp . Here is my model fm2 <- lme(CA ~ 1 + pF+Tiefe+BTyp+Tiefe:pF+BTyp:pF, data=data2, random = list(~ 1 + pF|Probe)) fm2_Btyphet<-update(fm2, weights=varIdent(form=~1|BTyp)) I managed to incorporate Btyp -specific variances for random effects using lmer function, but this function does not allow to consider variance heterogeneity of the within group error (which is