The user specifies a regression model and a variable for weighting, and `sm_regression`` will estimate a weighted regression model for each unique value of the specified variable.

sm_regression(data, method, formula, weighting_var, newdata = data,
  method.args = NULL, lambda = 1, kernel = "epanechnikov",
  dist.method = "euclidean", verbose = FALSE)

Arguments

data

data frame

method

function to use

formula

formula

weighting_var

columns name(s) of variables used to calculate weights

newdata

new data frame. Default is `data`.

method.args

List of additional arguments passed on to the modelling function defined by `method`

lambda

The radius of the kernel for tri-cubic, Epanechnikov, and flat kernels. The standard deviation for the Gaussian kernel

kernel

Specifies the kernel to be used: `epanechnikov`, `tricube`, `gaussian`, and `flat` are accepted. Default is `epanechnikov`

dist.method

Specifies the distance measure to be used in the kernel. Default is `euclidean`. Distance measures accepted by stats::dist is acceptable.

verbose

Return full set of results as an attribute. Default is `FALSE`

Examples

sm_regression( data = mtcars, method = "glm", formula = am ~ mpg, weighting_var = "mpg", method.args = list(family = binomial(link = "logit")) )
#> Warning in glm: non-integer #successes in a binomial glm!
#> # A tibble: 27 x 2 #> am mpg #> <dbl> <dbl> #> 1 1 21 #> 2 1 22.8 #> 3 0 21.4 #> 4 0 18.7 #> 5 0 18.1 #> 6 0 14.3 #> 7 0 24.4 #> 8 0 22.8 #> 9 0 19.2 #> 10 0 17.8 #> 11 0 16.4 #> 12 0 17.3 #> 13 0 15.2 #> 14 0 10.4 #> 15 0 14.7 #> 16 1 32.4 #> 17 1 30.4 #> 18 1 33.9 #> 19 0 21.5 #> 20 0 15.5 #> 21 0 13.3 #> 22 1 27.3 #> 23 1 26 #> 24 1 15.8 #> 25 1 19.7 #> 26 1 15 #> 27 1 21.4
#> # A tibble: 27 x 3 #> am mpg .model #> <dbl> <dbl> <list> #> 1 1 21 <S3: glm> #> 2 1 22.8 <S3: glm> #> 3 0 21.4 <S3: glm> #> 4 0 18.7 <S3: glm> #> 5 0 18.1 <S3: glm> #> 6 0 14.3 <S3: glm> #> 7 0 24.4 <S3: glm> #> 8 0 22.8 <S3: glm> #> 9 0 19.2 <S3: glm> #> 10 0 17.8 <S3: glm> #> # ... with 17 more rows