Description Usage Arguments Details Value Examples
focusing on selected variables in the model, and eliminating impacts from other variables.
| 1 2 | 
| model | an output of lm or glm | 
| focus_var_coeff | NULL or a character vector, choose coeff vars you want to focus. The unselected vars will have coeff values as 0. Default is NULL, which means to choosing nothing. | 
| focus_var_raw | NULL or a character vector, choose raw vars you want to focus. The unselected vars will have coeff values as 0. Default is NULL, which means to choosing nothing. | 
| intercept_include | a boolean, whether to include the intercept (default is TRUE). | 
| data | optional, a new dataset to evaluate the categorical variables. If NULL, then use the data used in model itself. | 
In a model y ~ a + b. Sometimes you want to fix value of a and see the variations of b in y.
The most straightforward way to code this, as we did in this function, is to make a's coefficients as 0, and then use the predict().
a new model with only focused vars having coeff unchanged, and all other vars having coeff as 0.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | focus_var_raw  = 'carat'
model = lm(price~ cut + carat + I(carat^2) + I(carat^3) +
             I(carat  * depth) + depth,ggplot2::diamonds)
# all coeffs except carat's will be 0
focusing_var_coeff(model, focus_var_coeff = 'carat')
# all coeffs except cut.L's will be 0
focusing_var_coeff(model, focus_var_coeff = 'cut.L')
# all coeffs without raw vars cut or carat will be 0
focusing_var_coeff(model, focus_var_raw = c('cut','carat'))
# if you didn't specify anything, then all vars' coeff will become 0 except intercept
focusing_var_coeff(model)
# if cannot find the focus_var_coeff or focus_var_raw in the model
tryCatch(focusing_var_coeff(model, focus_var_coeff = 'caratdsd'),
         error = function(err) warning(err))
tryCatch(focusing_var_coeff(model, focus_var_raw = '3213'),
         error = function(err) warning(err))
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.