robust standard errors in ggplot2

后端 未结 1 1467
半阙折子戏
半阙折子戏 2021-01-06 17:25

I would like to plot a model with ggplot2. I have estimated a robust variance-covariance matrix which I would like to use when estimating the confidence interval.

C

相关标签:
1条回答
  • 2021-01-06 17:55

    Only the standard errors, not the predictions, should change -- right?

    getvcov <- function(fm,dfcw,cluster) {
      library(sandwich);library(lmtest)
      M <- length(unique(cluster))   
      N <- length(cluster)           
      K <- fm$rank                        
      dfc <- (M/(M-1))*((N-1)/(N-K))  
      uj  <- apply(estfun(fm),2, function(x) tapply(x, cluster, sum));
      dfc*sandwich(fm, meat=crossprod(uj)/N)*dfcw
    }
    
    V <- getvcov(lm1,1,df$group)
    X <- as.matrix(model.frame(lm1))
    se <- predict(lm1,se=TRUE)$se.fit
    se_robust <- sqrt(diag(X %*% V %*% t(X)))
    
    0 讨论(0)
提交回复
热议问题