모델 적합 및 추정값 추정

choyunjeong·2025년 1월 12일

1. Fit models and obtain estimates

# Fit models
## Unadjusted
modelUnmatch <- glm(formula = Y ~ factor(Tr), data = data,       
				    family = quasipoisson())
    
## IPTW
modelIptw    <- svyglm(formula = Y ~ factor(Tr), design = iptwData, 
                       family = quasipoisson())
    
## MW
modelMw      <- svyglm(formula = Y ~ factor(Tr), design = mwData,   
                       family = quasipoisson())


# Return pairs of coef and vcov
library(sandwich)
U  = list(coef = coef(modelUnmatch), vcov = sandwich(modelUnmatch))
Ip = list(coef = coef(modelIptw),    vcov = vcov(modelIptw))
Mw = list(coef = coef(modelMw),      vcov = vcov(modelMw))

\\[40pt]

2. estimated coefficient, varaince-covariance, confidence interval

# Unadjusted
U  = list(coef = coef(modelUnmatch), vcov = sandwich(modelUnmatch))

## coefficient
coef = U$coef
coef[4] <- coef[3] - coef[2]
names(coef) <- c("Int","1v0","2v0","2v1")
coef

## varaince-covariance
vcov <- U$vcov
vars <- diag(vcov)
vars[4] <- vcov[2,2] + vcov[3,3] - 2 * vcov[2,3]
names(vars) <- names(coef)

## standard error
se    <- sqrt(vars[-1])

## confidence interval
lower <- coef[-1] - 1.95996 * se
upper <- coef[-1] + 1.95996 * se

z     <- coef[-1] / se

lstModelOut = list(coef = coef, vars = vars, lower = lower, upper = upper, z = z)

참고

0개의 댓글