get_x_hidden: the underlying function of 'get_x'

Description Usage Arguments Details Value See Also Examples

Description

the underlying function of get_x

Usage

1
get_x_hidden(model, method = c("raw", "model", "coeff"), data = NULL)

Arguments

model

method,data get_x

Details

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.

Value

get_x

See Also

get_x

Examples

 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
get_x_hidden(model = diamond_lm,method = 'raw')
get_x_hidden(diamond_lm,method = 'model')
get_x_hidden(diamond_lm,method = 'coeff')

#_______ input as formula
get_x_hidden(formula(diamond_lm),method = 'model')
# data is required when input is formula
get_x_hidden(formula(diamond_lm), data = ggplot2::diamonds, method = 'coeff')

tryCatch(
  get_x_hidden(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
get_x_hidden(model_dirty)

# correct for model vars
get_x_hidden(price~  I(carat^2) + cut  -
               carat:table - cut,
             data = ggplot2::diamonds, method ='model')

get_x_hidden(model_dirty,method = 'model')
get_x_hidden(model_dirty,data = ggplot2::diamonds, method = 'model')
get_x_hidden(model_dirty, method = 'model')

#___________ coeff vars __________

# clean
get_x_hidden(model_dirty, data = ggplot2::diamonds, method = 'coeff')
get_x_hidden(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()

Fan-Yang-Econ/linear.tools_github documentation built on May 6, 2019, 4:34 p.m.