Reliable standard errors in ggplot2

I would like to build a model with ggplot2. I appreciated the robust variance-covariance matrix that I would like to use in estimating the confidence interval.

Can I tell ggplot2 to use my VCOV, or, alternatively, can I somehow make sched.lm use my VCOV matrix? An example of a dummy example:

source("http://people.su.se/~ma/clmclx.R") df <- data.frame(x1 = rnorm(100), x2 = rnorm(100), y = rnorm(100), group = as.factor(sample(1:10, 100, replace=T))) lm1 <- lm(y ~ x1 + x2, data = df) coeftest(lm1) ## outputs coef.test, but can be modified to output VCOV clx(lm1, 1, df$group) 

It would be relatively easy to add to ggplot if I could get the β€œcorrect” predictions, given my extended VCOV matrix.

+3
source share
1 answer

Only standard errors, not 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)/(NK)) 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))) 
+4
source

Source: https://habr.com/ru/post/916295/


All Articles