Description Usage Arguments Details Value See Also Examples
the underlying function of get_x
1 |
model |
method,data |
This is the one of many underlying functions that powers get_x
.
The major difference is: get_x
can deal with dirty formula,
but get_x_hidden
cannot. 'dirty formula' means a formula with redundant terms,
such as y ~ x1 + x2 -x1
.
get_x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #
data = ggplot2::diamonds
diamond_lm = lm(price~ I(carat^ 2) + cut + carat*table ,ggplot2::diamonds)
#_________ input as model
(model = diamond_lm,method = 'raw')
(diamond_lm,method = 'model')
(diamond_lm,method = 'coeff')
#_______ input as formula
(formula(diamond_lm),method = 'model')
# data is required when input is formula
(formula(diamond_lm), data = ggplot2::diamonds, method = 'coeff')
tryCatch(
(formula(diamond_lm),method = 'coeff'),
error =function(err){
print(err)
}
)
#________ irregular formulas __________
model_dirty = model = lm(price~ I(carat^ 2) + cut -
carat:table - cut ,ggplot2::diamonds)
# WRONG for raw vars
(model_dirty)
# correct for model vars
(price~ I(carat^2) + cut -
carat:table - cut,
data = ggplot2::diamonds, method ='model')
(model_dirty,method = 'model')
(model_dirty,data = ggplot2::diamonds, method = 'model')
(model_dirty, method = 'model')
#___________ coeff vars __________
# clean
(model_dirty, data = ggplot2::diamonds, method = 'coeff')
(formula(model_dirty),data = ggplot2::diamonds, method = 'coeff')
#
# # dirty
# attr(terms((price~ I(carat^2) + cut + carat:table - cut)),"factors") %>% colnames()
#
# #______________ test: how to get variables
# model.matrix(formula(model_dirty),data = ggplot2::diamonds) %>% colnames
# terms(formula(diamond_lm)) %>% attr(.,"factors") %>% colnames()
# terms(formula(model_dirty)) %>% attr(.,"factors") %>% colnames()
# terms(formula(model_dirty)) %>% attr(.,"factors") %>% rownames()
#
#
# # clean method for model vars
# terms((price~ I(carat^2) + cut - carat:table - cut)) %>% attr(.,"factors") %>% colnames()
# model_dirty %>% terms %>% attr(.,"factors") %>% colnames()
# formula(model_dirty) %>% terms %>% attr(.,"factors") %>% colnames()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.