Multiple groups with Linear Quantile Mixed Models - r

I'm trying to fit a linear quantile mixed model with multiple group variables for random effects.
With lme4 in R, I can use
model <- lmer(target ~ feat1 + (1|feat2) + (1|feat3), data)
which gets me two set of random effects for both feat2 and feat3.
Is it possible to do anything similar for quantile models? Reading through the doc for lqmm, it seems it can only do one group variable?

Related

Multilevel model using glmer: Singularity issue

I'm using R to run a logistic multilevel model with random intercepts. I'm using the frequentist approach (glmer). I'm not able to use Bayesian methods due to the research centre's policy.
When I run my code it says that my model is singular. I'm not sure why or how to fix the issue. Any advice would be appreciated!
More information about the multilevel model I used:
I'm using a multilevel modelling method used in intersectionality research called multilevel analysis of individual heterogeneity and discriminatory accuracy (MAIHDA). The method uses individual level data as level 2 (the intersection group) and nests individuals within their intersections.
My outcome is binary and I have three categorical variables as fixed effects (gender, martial status, and disability). The random effect (level 2) is called intersect1 which includes each unique combination of the categorical variables (gender x marital x disability).
This is the code:
MAIHDA_full <- glmer(IPV_pos ~ factor(sexgender) + factor(marital) + factor(disability) + (1|intersect1), data=Data, family=binomial, control=glmerControl(optimizer=”bobyqa”,optCtrl=list(maxfun=2e5)))
The usual reason for a singular fit with mixed effects models is that either the random structure is overfitted - typically because of the inclusion of random slopes, or in the case such as this where we only have random intercepts, then the variation in the intercepts is so small that the model cannot detect it.
Looking at your model formula I suspect the issue is:
The random effect (level 2) is called intersect1 which includes each unique combination of the categorical variables (gender x marital x disability).
If I have understood this correctly, the model is equivalent to:
IPV_pos ~ sexgender + marital + disability + (1 | sexgender:marital:disability)
It is likely that any variation in sexgender:marital:disability is captured by the fixed effects, leading to near-zero variation in the random intercepts.
I suspect you will find almost identical results if you don't use any random effect.

R: post-hoc comparisons using estimated marginal means but not assuming equal variances

I am trying to use R to run post-hoc comparisons following a significant interaction for a mixed-method Anova. I would like to do the post-hoc similar to SPSS [EMMEANS=TABLES(Group*time) COMPARE(Group) ADJ(BONFERRONI)], using estimated marginal means but not assuming equality of variance.
Dependent variable = 'depvar'. I have 3 groups ('group') and 3 time points ('timept'), which are repeated measures over subjects ('id');
aov_car(depvar ~ group*timept + Error(id/(timept)), data=myData)
If I use pairwise.t.test I can compare groups separately for each time point, but the R uses observed means and I do not know how to force using the estimated marginal means of my model:
for (itimept in unique(myData$timept)){
idx=myData$timept==itimept
pairwise.t.test(myData$depvar[idx],myData$group[idx],p.adj="bonferroni")
}
If I use emmeans or lsmeans then R uses estimated marginal means, but assumes variances are the same (the SE in the results are all the same).
myfit=lme(depvar ~ group*timept, random = ~1|id/timept, data=myData)
emmeans(myfit, pairwise~group|timept, adjust="bonferroni")
How do I run post-hoc comparisons between groups for each time point, using estimated marginal means but not assuming equal variances, similar to SPSS?
Thanks!
Cristina
It isn’t emmeans that assumes equal variances. It is the model that you fitted and subsequently handed to emmeans for further analysis. Fit a different model using, I think, the weights argument, that specifies unequal variances.
I believe that this model will do the trick:
myfit = lme(depvar ~ group*timept,
random = ~1|id/timept,
weights = varFunc(~ group*timept),
data = myData)

Use FE estimates for OLS

I am analyzing a panel data set and I am interested in some time-independent explanatory variables(z). The Hausmann Test shows that I should use a fixed effects model instead of a random effects model.
Downside is, that the model will not estimate any coefficients for the time-independent explanatory variables.
So one idea is to take the estimated coefficients(b) for the time-dependent variables(x) from the FE model and use them on the raw data which means, take out the effects from the already estimated explanatory variables. Then use this corrected values as dependent variable for an OLS model with the time-independent variables as explanatory variables. This leads to:
y - x'b = z'j + u (with j as coefficients of interesst)
Do these two models exclude each other with any necessary assumption or is it just that the standard errors of the OLS model need to be corrected?
Thanks for every hint!

Use of multiple imputation in R for two-level binary logistic regression model

I am using the glmer function of the R library lme4 to fit a General Linear Mixed (GLM) models using the Laplace approximation and with a binary response variable, BINARY_r , say. I have one level two fixed effects variables (‘FIXED’, say) and two level two cross-classified random effects variables (‘RANDOM1’ and ‘RANDOM2’, say). The level one binary response variable, BINARY_r, is nested separately within each of the two level two variables. The logit function is used as a link function for representing the non-Gaussian nature of the response variable. The interactive effect between the two random effects variables is represented by ‘RANDOM1:RANDOM2’. All three independent variables are categorical. The model takes the form,
BINARY_r ~ FIXED + RANDOM1 + RANDOM2 + RANDOM1:RANDOM2.
There are missing data for ‘FIXED’ and ‘BINARY_r’ and I wish to explore the improvement in the model through applying multiple imputation for each of these two variables.
I am very unclear, however, as to how to use MI to generate a new function in R using glmer which is identical to the original one but now includes imputed data for FIXED and BINARY_r. Can you help, please?
Many thanks in advance

Can/Should I use the output of a log-linear model as the predictors in a logistic regression model?

I have a data set with both continuous and categorical variables. In the end I want to build a logistic regression model to calculate the probability of a response dichotomous variable.
Is it acceptable, or even a good idea, to apply a log linear model to the categorical variables in the model to test their interactions, and then use the indicated interactions as predictors in the logistic model?
Example in R:
Columns in df: CategoricalA, CategoricalB, CategoricalC, CategoricalD, CategoricalE, ContinuousA, ContinuousB, ResponseA
library(MASS)
#Isolate categorical variables in new data frame
catdf <- df[,c("CategoricalA","CategoricalB","CategoricalC", "CategoricalD", "CategoricalE")]
#Create cross table
crosstable <- table(catdf)
#build log-lin model
model <- loglm(formula = ~ CategoricalA * CategoricalB * CategoricalC * CategoricalD * CategoricalE, data = crosstable)
#Use step() to build better model
automodel <- step(object = model, direction = "backward")
Then build a logistic regresion using the output of automodeland the values of ContinuousA and ContinuousB in order to predict ResponseA (which is binary).
My hunch is that this is not ok, but I cant find the answer definitively one way or the other.
Short answer: Yes. You can use any information in the model that will be available in out-of-time or 'production' run of the model. Whether this information is good, powerful, significant, etc. is a different question.
The logic is that a model can have any type of RHS variable, be it categorical, continuous, logical, etc. Furthermore, you can combine RHS variables to create one RHS variable and also apply transformations. The log linear model of categorical is nothing by a transformed linear combination of raw variables (that happen to be categorical). This method would not be violating any particular modeling framework.

Resources