# NOT RUN {
library(SAMBA)
# These examples are generated from the vignette. See it for more details.
# Generate IPW weights from the true model
expit <- function(x) exp(x) / (1 + exp(x))
prob.WD <- expit(-0.6 + 1 * samba.df$D + 0.5 * samba.df$W)
weights <- nrow(samba.df) * (1 / prob.WD) / (sum(1 / prob.WD))
# Get initial parameter estimates
logit <- function(x) log(x / (1 - x))
fitBeta <- glm(Dstar ~ X, binomial(), data = samba.df)
fitTheta <- glm(Dstar ~ Z, binomial(), data = samba.df)
sens <- sensitivity(samba.df$Dstar, samba.df$X, mean(samba.df$D), r = 2)
start <- c(coef(fitTheta), logit(sens$c_marg), coef(fitBeta)[2])
# Direct observed data likelihood maximization without fixed intercept
# }
# NOT RUN {
fit1 <- obsloglik(samba.df$Dstar, samba.df$Z, samba.df$X, start = start,
weights = weights)
obsloglik1 <- list(param = fit1$param, variance = diag(fit1$variance))
# }
# NOT RUN {
# Direct observed data likelihood maximization with fixed intercept
# }
# NOT RUN {
fit2 <- obsloglik(samba.df$Dstar, samba.df$Z, samba.df$X, start = start,
beta0_fixed = logit(sens$c_marg), weights = weights)
# since beta0 is fixed, its variance is NA
obsloglik1 <- list(param = fit2$param, variance = diag(fit2$variance))
# }
Run the code above in your browser using DataLab