Search code examples
rregressionfixedglmrandom-effects

How to add random and/or fixed effects into cloglog regression in R


Update question on treatment of one variable for fixed effects I am planning to run a cloglog regression in R with random and/or fixed effects to check for unobserved heterogeneity. Now i have not found anything on how to do this in R only one function in Stata. Is anyone familiar with this? I have a variable zipcode which i would like to enter, this variable consists of 205 levels and i am kind of stuck on what to do.

This is an example of my cloglog regression:

    model_simple <- as.formula("completion_yesno ~  ac + ov + UCRate + FirstWeek + LastWeek + DayofWeekSu + DayofWeekMo + DayofWeekTu + DayofWeekWe + DayofWeekTh + DayofWeekFr + MonthofYearJan + MonthofYearFeb + MonthofYearMar + MonthofYearApr +MonthofYearMay+ MonthofYearJun + MonthofYearJul + MonthofYearAug + MonthofYearSep + MonthofYearOct + MonthofYearNov")
clog_simple1 = glm(model_simple,data=cllw,family = binomial(link = cloglog))
summary(clog_simple1)

I have tried to enter fixed effects with the glmmboost function from the package glmmML package

> model_simple <- as.formula("completion_yesno ~  ac + ov +
> UCRate + FirstWeek + LastWeek + DayofWeekSu + DayofWeekMo
> + DayofWeekTu + DayofWeekWe + DayofWeekTh + DayofWeekFr + MonthofYearJan + MonthofYearFeb + MonthofYearMar + MonthofYearApr
> +MonthofYearMay+ MonthofYearJun + MonthofYearJul + MonthofYearAug + MonthofYearSep + MonthofYearOct + MonthofYearNov") clog_fe <-
> glmmboot(model_simple, data=cllw,family = binomial(link = cloglog),
> cluster = zip, boot = 5000) summary(clog_fe)

The function just runs and never seems to come to an result. I am stuck and happy for every tip.


Solution

  • You can fit fixed-effects model with the standard glm function. You just need to create a dummy by level of interest. For instance, something in this flavor:

    Fixed effects

    model_FE <- as.formula("completion_yesno ~ factor(groupvar) + ac + ov + UCRate + FirstWeek + LastWeek + DayofWeekSu + DayofWeekMo + DayofWeekTu + DayofWeekWe + DayofWeekTh + DayofWeekFr + MonthofYearJan + MonthofYearFeb + MonthofYearMar + MonthofYearApr +MonthofYearMay+ MonthofYearJun + MonthofYearJul + MonthofYearAug + MonthofYearSep + MonthofYearOct + MonthofYearNov")
    glm(model_simple,data=cllw,family = binomial(link = cloglog))
    

    factor(group) will create K-1 (or K if you want to fit the model without intercept) coefficients.

    Random effects

    You must use another package lme4 that proposes a function for that glmer. You can find some information here and here