PSmethod_SW | R Documentation |
The function PSmethod_SW
is an internal function to estimate the propensity scores given a specified model through formula.
It is built into function Sumstat_SW
, PStrim_SW
and PSweight_SW
.
PSmethod_SW(
ps.formula = ps.formula,
method = "glm",
data = data,
survey.weight = survey.weight,
ncate = ncate,
ps.control = list()
)
ps.formula |
an object of class |
method |
a character to specify the method for estimating propensity scores. |
data |
an optional data frame containing the variables in the propensity score model. |
survey.weight |
an numeric vector specifying survey weights for each observation. |
ncate |
a numeric to specify the number of treatment groups present in the given data. |
ps.control |
a list to specify additional options when |
A typical form for ps.formula
is treatment ~ terms
where treatment
is the treatment
variable and terms
is a series of terms which specifies a linear predictor. ps.formula
by default specifies generalized
linear models given the default argument method = "glm"
. It fits the logistic regression when ncate = 2
,and multinomial
logistic regression when ncate > 2
. The argument method
allows user to choose
model other than glm to fit the propensity score models. We have included gbm
and SuperLearner
as two alternative machine learning methods.
Additional arguments of the machine learning estimators can be supplied through the ...
argument. Note that SuperLearner does not handle multiple groups and the current version of multinomial
logistic regression is not supported by gbm. We suggest user to use them with extra caution. Please refer to the user manual of the gbm
and SuperLearner
packages for all the
allowed arguments.
e.h
a data frame of estimated propensity scores.
ps.fitObjects
the fitted propensity model details
beta.h
estimated coefficient of the propensity model when method = "glm"
.
# Load example datasets
data("psdata")
data("psdata_bin_prospective_fp")
data("psdata_bin_retrospective_fp")
# Define the propensity score model.
ps.formula <- trt ~ cov1 + cov2 + cov3 + cov4 + cov5 + cov6
# Extract the survey weights from the retrospective data.
survey.weight <- psdata_bin_retrospective_fp$survey_weight
# Specify the number of treatment groups (for binary treatment, ncate = 2)
ncate <- 2
# Fit the propensity score model using PSmethod_SW.
psfit <- PSmethod_SW(ps.formula = ps.formula,
data = psdata_bin_retrospective_fp,
survey.weight = survey.weight,
ncate = ncate)
# Print the first 10 rows of the estimated propensity scores.
cat("Estimated propensity scores (first 10 observations):\n")
print(head(psfit$e.h, 10))
# For the 'glm' method, print the estimated coefficient vector.
cat("\nEstimated coefficients (beta.h):\n")
print(psfit$beta.h)
# Users can also inspect the full fitted model object.
cat("\nFitted propensity model object summary:\n")
print(summary(psfit$ps.fitObjects))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.