estweight | R Documentation |
Estimate propensity weights for biased samples using information from a representative sample.
estweight( data, weight_model = "logistic", incl_wts_for_rep = FALSE, return_model_fit = FALSE )
data |
Combined dataset including the convenience sample and representative sample with a subject
identifier, |
weight_model |
Which propensity weight estimation model should be used. Either |
incl_wts_for_rep |
A logical value indicating whether propensity weights for observations from the representative sample should be included in the output. |
return_model_fit |
An optional flag which changes the output so that it returns a list of estimated propensity weights and the model fit. This is useful for downstream uncertainty estimates. Note that a model fit is only returned if a logistic propensity weight estimation model is selected (weight_model == "logistic") |
estweight
returns a dataframe containing IDs and the corresponding estimated
propensity weights. If the flag return_model_fit == TRUE and the weight_model == "logistic", it instead returns a list where the
first element is the dataframe of IDS and weights and the second element is the model fit.
#' data("mtcars") repsample = mtcars n = nrow(repsample) expit = function(x) {exp(x) / (1 + exp(x))} # Calculate probability of being oversampled repsample$sampprob = expit(.01*(repsample$am*4 + repsample$carb*3 + repsample$drat*.9 -repsample$mpg*repsample$disp*.05 + .002*repsample$hp^2 + 80)) # draw biased and representative samples b.samp = repsample[sample(1:n, 500, prob = repsample$sampprob, replace = TRUE), ] r.samp = repsample[sample(1:n, 500, replace = TRUE), ] # Create indicator of biased sample membership b.samp$biased = 1; r.samp$biased = 0 # Format data to pass to function Xcomb = data.frame(ID = 1:(1000), rbind(b.samp, r.samp)) Xfit = Xcomb[,c("ID", colnames(Xcomb)[c(2:8,10:12)], "biased")] # Estimate propensity weights estweight(data = Xfit, weight_model = "logistic")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.