To explain my problem , i have this simulated data using R.
require(splines)
x=rnorm(20 ,0,1)
y=rep(c(0,1),times=10)
First i fitted a regular (linear effects) logistic regression model.
fit1=glm(y~x ,family = "binomial")
Then to check the non linear effects, i fitted this natural spline model .
fit2=glm(y~ns(x,df=2) ,family = "binomial")
Based on my thinking models , i believe these 2 models are non nested models.
Next i wanted check whether the non linear model (fit2) has any significant effects compared to the regular logistic model (fit1).
Is there any way to compare this two models? I believe i cannot use the lrtest function in lmtest package, because these two models are not nested models.
Any suggestion will be highly appreciated
Thank you.
Related
I would like to estimate a random effects (RE) multinomial logit model.
I have been applying mblogit from the mclogit package. However, once I introduce RE into my model, it fails to converge.
Is there a workaround this?
For instance, I tried to adjust the fitting process of mblogit and increase the maximal number of iterations (maxit), but did not succeed to correctly write the syntax for the control function. Would this be the right approach? And if so, could you advise me how to implement it into my model which so far looks as follows:
meta.mblogit <- mblogit(Migration ~ ClimateHazard4 , weights = logNsquare,
data = meta.df, subset= Panel==1, random = ~1|StudyID,
)
Here, both variables (Migration and ClimateHazard4) are factor variables.
Or is there an alternative approach you could recommend me for an estimation of RE multinomial logit?
Thank you very much!
I am trying to run a Generalized linear mixed model (GLMM) on r, I have two fixed factors and two random factors
however there are a lot of holes in my data set and the I am struggling to find a code to run the glmm all I found is the glm
Can someone please walk me through this, I know very little about R and coding
You can use the lme4 package as well. The command for a generalized linear mixed model is glmer().
Example:
install.packages("lme4") #If you still haven't done it.
library(lme4)
myfirstmodel <- glmer(variable_to_study ~ fixed_variable + (1|random_effect_varible), data = mydataset, family = poisson)
Family = poisson was just an example. Choose the 'family' according to the nature of the variable_to_study (eg. poisson for discrete data).
I am fitting a heterogeneous linear mixed effect model which is in the lcmm package in R. Currently, I am only getting the class-specific and weighted subject-specific prediction from the predictY function. But, I want a subject-specific prediction. Is there any way to construct a subject-specific prediction from this package? Any help is appreciated.
I have found the answer. Looks like PredictY gives the mean class-specific predictions and adding them with the multiplication of the random effects from each subject (ranef(model)) and the model design matrix for the random part will provide the subject-specific prediction.
I've fit two models, one with gam and another with gamm.
gam(y ~ x, family= betar)
gamm(y ~ x)
So the only difference is the distributional assumption. I use betar with gam and normal with gamm.
I would like to compare these two models, but I am guessing AIC will not work since the two models are based on different methods? Is there then some other suitable estimate I can use for comparison? I know I could just fit the second with gam, but let's ignore that for the sake of this question.
AIC is independent of the type of model used as soon as y is exactly the same observation to be predicted. This is only a computation of deviance explained penalised by the number of parameters fitted.
However, depending on the goal of your model, if you want to be able to use the model for prediction for instance, you should use validation to compare model performance. 10-fold cross-validation would be a good idea for instance.
I am trying to analyze a longitudinal data with binary response using 3-level logistic regression. Hierarchical structure of my data looks like this example- students (level 1) are nested within a class(level 2) and the classes are nested within a school (level 3).
Can anyone suggest me some appropriate readings on the SAS or R codes for performing 3-level mixed effects logistic regression? I am not requesting helps regarding the theory behind 3-level logistic regression. Any examples with SAS or R codes would be of great help.
In R you can use the glmer() function from the lme4 package for mixed effects models. You specify the effects in the formula= option. For nested random effects you probably want something like:
model <- glmer(formula = response ~ (1|student|class/block), family=binomial)
There are some examples of multi-level models on R-sessions
and you can fit non-linear responses, such as binomial, with family=binomial.