Like a derivative or finite-difference
mod_effect(model, formula, step = NULL, bootstrap = 0, to = step, nlevels = 1, data = NULL, at = NULL, class_level = NULL, ...)
model | the model from which the effect size is to be calculated |
---|---|
formula | a formula whose right-hand side is the variable with respect to which the effect size is to be calculated. |
step | the numerical stepsize for the change var, or a comparison category for a categorical change var. This will be either a character string or a number, depending on the type of variable specified in the formula. |
bootstrap | The number of bootstrap replications to construct. If greater than 1, calculate a standard error using that number of replications. |
to | a synonym for step. (In English, "to" is more appropriate for a categorical input, "step" for a quantitative. But you can use either.) |
nlevels | integer specifying the number of levels to use for "typical" inputs. (Default: up to 3) |
data | Specifies exactly the cases at which you want to calculate the effect size. |
at | similar to |
class_level | Name of the categorical level for which the probability is to be used. Applies
only to classifiers. (Default: Use the first level.)
Unlike |
... | additional arguments for evaluation levels of explanatory variables. |
a data frame giving the effect size and the values of the explanatory variables at which
the effect size was calculated. There will also be a column to_
showing the value jumped to for the
variable with respect to which the effect size is calculated. When bootstrap
is greater than 1, there will
be a standard error reported on the effect size; see the variable ending in _se
.
When you want to force or restrict the effect size calculation to specific values for
explanatory variables, list those variables and levels as a vector in ...
For example, educ = c(10, 12, 16)
will cause the effect size to be calculated
at each of those three levels of education. Any variables whose levels are not specified in
... will have values selected automatically.
#> change sex to_sex age educ sector #> 1 -1.875015 M F 35 12 profmod_effect(mod1, ~ sector)#> change sector to_sector age sex educ #> 1 -2.232965 prof clerical 35 M 12mod_effect(mod1, ~ age, sex = "M", educ = c(10, 12, 16), age = c(30, 40))#> slope age to_age sex educ sector #> 1 0.1181573 30 40 M 10 prof #> 2 0.1181573 40 50 M 10 prof #> 3 0.1381628 30 40 M 12 prof #> 4 0.1381628 40 50 M 12 prof #> 5 0.1781739 30 40 M 16 prof #> 6 0.1781739 40 50 M 16 profmod_effect(mod1, ~ age, sex = "F", age = 34, step = 1)#> slope age to_age sex educ sector #> 1 0.054897 34 35 F 12 profmod_effect(mod1, ~ sex, age = 35, sex = "M", to = "F" )#> change sex to_sex age educ sector #> 1 -1.875015 M F 35 12 prof# For classifiers, the change in *probability* of a level is reported. mod2 <- rpart::rpart(sector ~ age + sex + educ + wage, data = mosaicData::CPS85) mod_effect(mod2, ~ educ)#> slope_clerical educ to_educ age sex wage #> 1 0 12 14 35 M 7.8mod_effect(mod2, ~ educ, class_level = "manag")#> slope_manag educ to_educ age sex wage #> 1 0 12 14 35 M 7.8