Skip to contents

These functions provide pipe-friendly wrappers around model fitters provided by several external packages. The functions require the corresponding packages to be installed, if the required package is missing the functions warns with directions for how to install it.

zlm_robust() wraps estimatr::lm_robust(), which fits a linear model with a variety of options for estimating robust standard errors.

zpolr() wraps MASS::polr(), which fits an ordered logistic response for multi-value ordinal variables, using a proportional odds logistic regression.

zplsr() wraps pls::plsr(), which performs a partial least squares regression.

Examples

if (requireNamespace("estimatr") && getRversion() >= "4.1.0")
  zlm_robust(cars, dist ~ speed) |> summary() |> try()
#> 
#> Call:
#> lm_robust(formula = dist ~ speed, data = cars)
#> 
#> Standard error type:  HC2 
#> 
#> Coefficients:
#>             Estimate Std. Error t value  Pr(>|t|) CI Lower CI Upper DF
#> (Intercept)  -17.579     5.7323  -3.067 3.551e-03  -29.105   -6.053 48
#> speed          3.932     0.4128   9.526 1.211e-12    3.102    4.762 48
#> 
#> Multiple R-squared:  0.6511 ,	Adjusted R-squared:  0.6438 
#> F-statistic: 90.75 on 1 and 48 DF,  p-value: 1.211e-12

if (requireNamespace("MASS") && getRversion() >= "4.1.0")
  zpolr(mtcars, ordered(gear) ~ mpg + hp) |> summary() |> try()
#> 
#> Re-fitting to get Hessian
#> Call:
#> polr(formula = ordered(gear) ~ mpg + hp, data = mtcars)
#> 
#> Coefficients:
#>       Value Std. Error t value
#> mpg 0.37279   0.123027   3.030
#> hp  0.02002   0.009634   2.078
#> 
#> Intercepts:
#>     Value   Std. Error t value
#> 3|4 10.1578  3.6605     2.7750
#> 4|5 12.7982  4.0427     3.1657
#> 
#> Residual Deviance: 51.16071 
#> AIC: 59.16071 

if (requireNamespace("pls") && getRversion() >= "4.1.0")
  zplsr(cars, dist ~ speed) |> summary() |> try()
#> Data: 	X dimension: 50 1 
#> 	Y dimension: 50 1
#> Fit method: kernelpls
#> Number of components considered: 1
#> TRAINING: % variance explained
#>       1 comps
#> X      100.00
#> dist    65.11