| pclass | R Documentation |
Fit a binary regression model for response probabilities and divide units into a specified number of classes.
pclass(formula, data, link="logit", numcl=5, type, design=NULL, seed=NULL, rng.preds=0.05)
formula |
symbolic description of the binary regression model to be fitted as used in |
data |
an optional data frame containing columns for a response variable and covariates used in the model to predict response propensities; must be specified if |
link |
a specification for the model link function; allowable values are |
numcl |
number of classes into which units are split based on estimated propensities |
type |
whether an unweighted or weighted binary regression should be fit; allowable values are |
design |
sample design object; required if |
seed |
random number seed |
rng.preds |
cutoff value for the range of the predicted response probabilities |
A typical formula has the form response ~ terms where response is a two-level variable coded as 0 or 1, or is a factor where
the first level denotes nonresponse and the second level is response. If type="unwtd",
glm is used to fit an unweighted regression. If type="wtd", svyglm in the survey package is used to
fit a survey-weighted regression. The jitter function is used to perturb regression predictions slightly. To reproduce the same set of weights in
different runs, set seed to some non-null integer. Recommended seeds can be found in positions 3:626 of the built-in global vector
.Random.seed.
If the range (defined as max - min) of the predicted response probabilities is less than rng.preds, the predictions are considered to have no
meaningful variation and a single response adjustment class is returned. rng.preds is adjustable to accomodate different user preferences.
A list with components:
p.class |
propensity class for each unit |
propensities |
estimated response probability for each unit |
Richard Valliant, Jill A. Dever, Frauke Kreuter
Valliant, R., Dever, J., Kreuter, F. (2018, chap. 13). Practical Tools for Designing and Weighting Survey Samples, 2nd edition. New York: Springer.
NRadjClass
# classes based on unweighted logistic regression
require(PracTools)
data(nhis)
out <- pclass(formula = resp ~ age + as.factor(sex) + as.factor(hisp) + as.factor(race),
data = nhis, type = "unwtd", link = "logit", numcl = 5, seed = 1387014860,
rng.preds = 0.05)
table(out$p.class, useNA="always")
summary(out$propensities)
# classes based on survey-weighted logistic regression
require(survey)
nhis.dsgn <- svydesign(ids = ~psu, strata = ~stratum, data = nhis, nest = TRUE, weights = ~svywt)
out <- pclass(formula = resp ~ age + as.factor(sex) + as.factor(hisp) + as.factor(race),
type = "wtd", design = nhis.dsgn, link="logit", numcl=5)
table(out$p.class, useNA="always")
summary(out$propensities)
# degenerate case where all response propensities are the same
df <- data.frame(resp = rbinom(500, 1, 0.75), x = rnorm(500))
out1 <- pclass(resp ~ 1, data = df, type = "unwtd", numcl = 5, rng.preds = 0.05)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.