| ps_weights | R Documentation |
Fits (or takes) a logistic regression for a binary treatment and returns inverse-probability
weights together with the influence of the fitted coefficients and the derivative of each weight
in those coefficients. Passed as weight_model to df_counting(), KM_diff(),
cumulative_rmst_bands() or plotKM.band_subgroups() with weight_variance = "estimated",
the object lets standard errors, intervals, bands and tests account for the fact that the
weights were estimated (see the section "Estimated weights" of df_counting()).
ps_weights(
formula = NULL,
data = NULL,
type = c("ipw", "stabilized"),
model = NULL
)
## S3 method for class 'ps_weights'
print(x, digits = 4, ...)
formula |
A formula for the treatment model, treatment (coded 0/1) on the left-hand side.
Used with |
data |
Data frame holding the variables of |
type |
|
model |
An existing logistic |
x |
A |
digits |
Number of significant digits to print. |
... |
Not used. |
With x_i the row of the model matrix of subject i, A_i the treatment and
e_i the fitted probability,
IF_i = \Big\{\sum_j x_j x_j' e_j (1 - e_j)\Big\}^{-1} x_i (A_i - e_i)
is the influence of subject i on the fitted coefficients (the estimate minus its limit is
approximately \sum_i IF_i), and the derivative of the weight of subject i
in the coefficients is
dw_i = -\{(1 - e_i) / e_i\} x_i for a treated subject and
dw_i = \{e_i / (1 - e_i)\} x_i for a control. With
type = "stabilized" the weights and dw are those of "ipw" multiplied by the arm proportion,
which is treated as a fixed number; IF is the same.
The following are errors, each naming the problem: a model that is not a glm; a family other
than binomial or a link other than logit; prior weights other than 1 or an offset; a fit that did
not converge; a fitted probability within 1e-10 of 0 or 1; rows dropped for missing values; a
response that does not take both values 0 and 1.
The weights are never truncated or rescaled. The rows of weights, treat, ps, IF and dw
are in the order of the rows of the data the model was fitted on.
An object of class "ps_weights", a list with
The weights, one per row.
"ipw" or "stabilized".
The treatment (0/1), one per row.
The fitted probabilities of treatment.
Matrix, one row per subject and one column per estimated coefficient (aliased columns dropped): the influence of each subject on the coefficients.
Matrix of the same shape: the derivative of each weight in the coefficients.
The glm fit.
The call.
print() shows the type, the number of rows and of coefficients, and by arm the size, the range
of the weights and the effective sample size (\sum w)^2 / \sum w^2.
df_counting() (section "Estimated weights"), KM_diff(), cox_rhogamma()
Other survival_analysis:
KM_diff(),
cox_rhogamma(),
df_counting(),
wt.rg.S()
library(survival)
gbsg$tte <- gbsg$rfstime / 30.4375
pw <- ps_weights(hormon ~ age + meno + size + grade + nodes + pgr + er, data = gbsg,
type = "stabilized")
pw
gbsg$sw <- pw$weights
# weights treated as known (the default) and with their estimation carried through
known <- KM_diff(gbsg, "tte", "status", "hormon", weight.name = "sw")
est <- KM_diff(gbsg, "tte", "status", "hormon", weight.name = "sw",
weight_variance = "estimated", weight_model = pw)
identical(known$dhat, est$dhat) # estimates do not change
summary(sqrt(est$sig2_dhat / known$sig2_dhat)) # standard errors do
dc <- df_counting(gbsg, "tte", "status", "hormon", weight.name = "sw",
weight_variance = "estimated", weight_model = pw)
dc$ess # effective sample size by arm
cox_rhogamma(dc, scheme = "fh", scheme_params = list(rho = 0, gamma = 0))$hr_ci_asy
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.