Logistic regression with robust clustered standard errors in R

logistic regression with clustered standard errors in r
glm.cluster r
clustered standard errors in r glm
probit clustered standard errors r
huber white clustered standard errors r
robust standard errors vs clustered standard errors
cluster robust standard errors in r glm
stata clustered standard errors

A newbie question: does anyone know how to run a logistic regression with clustered standard errors in R? In Stata it's just logit Y X1 X2 X3, vce(cluster Z), but unfortunately I haven't figured out how to do the same analysis in R. Thanks in advance!

You might want to look at the rms (regression modelling strategies) package. So, lrm is logistic regression model, and if fit is the name of your output, you'd have something like this:

fit=lrm(disease ~ age + study + rcs(bmi,3), x=T, y=T, data=dataf)

fit

robcov(fit, cluster=dataf$id)

bootcov(fit,cluster=dataf$id)

You have to specify x=T, y=T in the model statement. rcs indicates restricted cubic splines with 3 knots.

[PDF] Package 'clusterSEs', September 15, 2019. Title Calculate Cluster-Robust p-Values and Confidence Intervals Depends R (>= 3.3.0), AER, Formula, plm, stats Code to estimate GLM clustered standard errors by Mahmood Arai: logit.model <- glm(degree ~ religion + gender + age, data=WVS, family=binomial(link="logit")). For calculating robust standard errors in R, both with more goodies and in (probably) a more efficient way, look at the sandwich package. The same applies to clustering and this paper . However, here is a simple function called ols which carries out all of the calculations discussed in the above.

I have been banging my head against this problem for the past two days; I magically found what appears to be a new package which seems destined for great things--for example, I am also running in my analysis some cluster-robust Tobit models, and this package has that functionality built in as well. Not to mention the syntax is much cleaner than in all the other solutions I've seen (we're talking near-Stata levels of clean).

So for your toy example, I'd run:

library(Zelig)
logit<-zelig(Y~X1+X2+X3,data=data,model="logit",robust=T,cluster="Z")

Et voilà!

[R] Logistic regression and robust standard errors, [R] Logistic regression and robust standard errors coeftest(model, vcov= vcovCL(model, cluster=mydata$ID)) > > First I got this error: > > Error� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

There is a command glm.cluster in the R package miceadds which seems to give the same results for logistic regression as Stata does with the option vce(cluster). See the documentation here.

In one of the examples on this page, the commands

mod2 <- miceadds::glm.cluster(data=dat, formula=highmath ~ hisei + female,
                              cluster="idschool", family="binomial")
summary(mod2)

give the same robust standard errors as the Stata command

logit highmath hisei female, vce(cluster idschool)

e.g. a standard error of 0.004038 for the variable hisei.

Obtaining robust standard errors and odds ratios for logistic , Obtaining robust standard errors and odds ratios for logistic regression in R. PUBLISHED ON SEP 19, 2016. I've always found it frustrating how it's so easy to � Celso Barros wrote: > I am trying to get robust standard errors in a logistic regression. Is there > any way to do it, either in car or in MASS? > > Thanks for the help, > > Celso One way to do it is to install the Hmisc and Design packages then f <- lrm(y ~ rcs(age,5)*sex+race, x=TRUE, y=TRUE) g <- robcov(f) # replaces variance-covariance matrix with sandwich estimator; can also adjust for

Another alternative would be to use the sandwich and lmtest package as follows. Suppose that z is a column with the cluster indicators in your dataset dat. Then

# load libraries
library("sandwich")
library("lmtest")

# fit the logistic regression
fit = glm(y ~ x, data = dat, family = binomial)

# get results with clustered standard errors (of type HC0)
coeftest(fit, vcov. = vcovCL(fit, cluster = dat$z, type = "HC0"))

will do the job.

Analysis of Clustered Data, Cluster-Robust SE, Fixed Effect, or Multilevel Models; An Example of Logistic x 0.01 0.02 ## --- ## n = 1000, k = 2 ## residual sd = 0.93, R-Squared = 0.00 Though the clustered-robust SEs correct the standard errors in linear regression, Let us replicate and expand the logistic regression explained by� Nonlinear Gmm with R - Example with a logistic regression Simulated Maximum Likelihood with R Bootstrapping standard errors for difference-in-differences estimation with R Careful with tryCatch Data frame columns as arguments to dplyr functions Export R output to a file I've started writing a 'book': Functional programming and unit testing for

lm.cluster function, Computes cluster robust standard errors for linear models ( stats::lm ) and general cluster=dat$idschool) summary(mod1b) #*** Model 2: Logistic regression� I am trying to estimate an ordinal logistic regression with clustered standard errors using the MASS package's polr() function. There is no built-in clustering feature, so I am looking for (a) packages or (b) manual methods for calculating clustered standard errors using the model output .

Cluster-robust Logistic Regression, Hey team, I have a binary dependent variable and would like to do an analysis with cluster-robust standard errors. Is this possible in the� This note deals with estimating cluster-robust standard errors on one and two dimensions using R (seeR Development Core Team[2007]). Cluster-robust stan-dard errors are an issue when the errors are correlated within groups of observa-tions. For discussion of robust inference under within groups correlated errors, see

[PDF] Robust and Clustered Standard Errors, An Introduction to Robust and Clustered Standard Errors. Outline. 1. An Introduction to Robust and Clustered Standard Errors. Linear Regression with Non-constant Variance Replicating in R than in the logit, so use:. Logistic regression and robust standard errors. Dear all, I use ”polr” command (library: MASS) to estimate an ordered logistic regression. My model: summary( model<- polr(y ~ x1+x2+x3+x4+x1*x2

Comments
  • the vcovHC() function in the sandwich package might also be useful (not sure if it applies to logistic regression estimates)
  • if you're migrating from Stata you might find the package called plm useful. Also, there is the package called pcse for implementing panel corrected standard errors by manipulating the variance covariance matrix after estimation
  • Thank you very much for your replies, Ben and Hubert. I will also test the packages you have suggested and see if they work with logistic estimates. Thanks again!
  • Thank you very much! It has worked wonders! I will read rms's manual more closely and see if there is a way of clustering the coefficients by country and also by year. Once again, thank you!
  • This answer is already very good but it could be improved if it was fully replicable. I have not idea where the variables come from, what the output is, and why rcs(bmi,3) is necessary.
  • Wow, that does appear to "just work" in ways that my R code never seems to. Is this new functionality? If not, why has Zelig not been the canonical way to solve this in R?
  • Don't know, but I hope it becomes so. The project certainly seems ambitious! The [Google group]( groups.google.com/forum/m/#!forum/zelig-statistical-software) doesn't seem so active though, so not sure how quick progress is.
  • Unfortunately, I think the command doesn't work in the latest version of Zelig (on CRAN). I've just run a few models with and without the cluster argument and the standard errors are exactly the same. I believe it's been like that since version 4.0, the last time I used the package.
  • yes, indeed they've dropped that functionality for now. check their google group (go to the community section of their website)--they're in the middle of restructuring the whole project; one of the developers said in reply to a post of mine that they're working on bringing back cluster/robust functionality
  • About three years later, cluster functionality is not back: Error in glm.control(cluster = "group") : unused argument (cluster = "group").