1
1
skip_if_not_installed(" panelr" )
2
+ skip_if_not_installed(" clubSandwich" )
3
+ skip_if_not_installed(" car" )
2
4
3
5
data(" teen_poverty" , package = " panelr" )
4
6
teen <- panelr :: long_panel(teen_poverty , begin = 1 , end = 5 )
@@ -9,138 +11,38 @@ test_that("model_info", {
9
11
})
10
12
11
13
test_that(" id_mixed" , {
12
- expect_true(is_mixed_model(m1 ))
13
- expect_true(is_mixed_model(m2 ))
14
+ expect_false(is_mixed_model(m1 ))
14
15
})
15
16
16
17
test_that(" find_predictors" , {
17
18
expect_identical(
18
19
find_predictors(m1 ),
19
- list (
20
- conditional = c(" union" , " wks" ),
21
- instruments = c(" blk" , " fem" ),
22
- interactions = c(" blk" , " union" )
23
- )
20
+ list (conditional = c(" pov" , " spouse" , " wave" ))
24
21
)
25
22
expect_identical(
26
23
find_predictors(m1 , flatten = TRUE ),
27
- c(" union " , " wks " , " blk " , " fem " )
24
+ c(" pov " , " spouse " , " wave " )
28
25
)
29
26
expect_null(find_predictors(m1 , effects = " random" ))
30
-
31
- expect_identical(
32
- find_predictors(m2 ),
33
- list (
34
- conditional = c(" union" , " wks" ),
35
- instruments = c(" blk" , " t" )
36
- )
37
- )
38
- expect_identical(find_predictors(m2 , effects = " random" ), list (random = " id" ))
39
27
})
40
28
41
29
test_that(" find_random" , {
42
30
expect_null(find_random(m1 ))
43
- expect_identical(find_random(m2 ), list (random = " id" ))
44
- })
45
-
46
- test_that(" get_random" , {
47
- expect_warning(expect_null(get_random(m1 )))
48
- expect_identical(get_random(m2 )[[1 ]], model.frame(m2 )$ id )
49
31
})
50
32
51
33
test_that(" find_response" , {
52
- expect_identical(find_response(m1 ), " lwage" )
53
- })
54
-
55
- test_that(" get_response" , {
56
- expect_identical(get_response(m1 ), model.frame(m1 )$ lwage )
57
- })
58
-
59
- test_that(" get_predictors" , {
60
- expect_identical(
61
- colnames(get_predictors(m1 )),
62
- c(" lag(union)" , " wks" , " blk" , " fem" )
63
- )
64
- expect_identical(
65
- colnames(get_predictors(m2 )),
66
- c(" lag(union)" , " wks" , " blk" , " t" )
67
- )
34
+ expect_identical(find_response(m1 ), " hours" )
68
35
})
69
36
70
37
test_that(" link_inverse" , {
71
38
expect_equal(link_inverse(m1 )(0.2 ), 0.2 , tolerance = 1e-5 )
72
39
})
73
40
74
- test_that(" clean_parameters" , {
75
- cp <- clean_parameters(m1 )
76
- expect_identical(
77
- cp $ Cleaned_Parameter ,
78
- c(
79
- " union" , " wks" , " (Intercept)" , " imean(lag(union))" , " imean(wks)" ,
80
- " blk" , " fem" , " union:blk"
81
- )
82
- )
83
- expect_identical(
84
- cp $ Component ,
85
- c(
86
- " conditional" , " conditional" , " instruments" , " instruments" ,
87
- " instruments" , " instruments" , " instruments" , " interactions"
88
- )
89
- )
90
- })
91
-
92
- test_that(" get_data" , {
93
- expect_identical(nrow(get_data(m1 )), 3570L )
94
- expect_identical(
95
- colnames(get_data(m1 )),
96
- c(
97
- " lwage" ,
98
- " id" ,
99
- " t" ,
100
- " lag(union)" ,
101
- " wks" ,
102
- " blk" ,
103
- " fem" ,
104
- " imean(lag(union))" ,
105
- " imean(wks)" ,
106
- " imean(lag(union):blk)" ,
107
- " lag(union):blk"
108
- )
109
- )
110
- expect_identical(
111
- colnames(get_data(m2 )),
112
- c(
113
- " lwage" ,
114
- " id" ,
115
- " t" ,
116
- " lag(union)" ,
117
- " wks" ,
118
- " blk" ,
119
- " imean(lag(union))" ,
120
- " imean(wks)"
121
- )
122
- )
123
- })
124
-
125
41
test_that(" find_formula" , {
126
- expect_length(find_formula(m1 ), 3 )
42
+ expect_length(find_formula(m1 ), 1 )
127
43
expect_equal(
128
44
find_formula(m1 ),
129
- list (
130
- conditional = as.formula(" lwage ~ lag(union) + wks" ),
131
- instruments = as.formula(" ~blk + fem" ),
132
- interactions = as.formula(" ~blk * lag(union)" )
133
- ),
134
- ignore_attr = TRUE
135
- )
136
-
137
- expect_equal(
138
- find_formula(m2 ),
139
- list (
140
- conditional = as.formula(" lwage ~ lag(union) + wks" ),
141
- instruments = as.formula(" ~blk + t" ),
142
- random = as.formula(" ~t | id" )
143
- ),
45
+ list (conditional = as.formula(" hours ~ lag(pov) + spouse + wave" )),
144
46
ignore_attr = TRUE
145
47
)
146
48
})
@@ -149,35 +51,18 @@ test_that("find_variables", {
149
51
expect_identical(
150
52
find_variables(m1 ),
151
53
list (
152
- response = " lwage" ,
153
- conditional = c(" union" , " wks" ),
154
- instruments = c(" blk" , " fem" ),
155
- interactions = c(" blk" , " union" )
54
+ response = " hours" ,
55
+ conditional = c(" pov" , " spouse" , " wave" )
156
56
)
157
57
)
158
58
expect_identical(
159
59
find_variables(m1 , flatten = TRUE ),
160
- c(" lwage" , " union" , " wks" , " blk" , " fem" )
161
- )
162
-
163
- expect_identical(
164
- find_variables(m2 ),
165
- list (
166
- response = " lwage" ,
167
- conditional = c(" union" , " wks" ),
168
- instruments = c(" blk" , " t" ),
169
- random = " id"
170
- )
171
- )
172
- expect_identical(
173
- find_variables(m2 , flatten = TRUE ),
174
- c(" lwage" , " union" , " wks" , " blk" , " t" , " id" )
60
+ c(" hours" , " pov" , " spouse" , " wave" )
175
61
)
176
62
})
177
63
178
64
test_that(" n_obs" , {
179
- expect_identical(n_obs(m1 ), 3570L )
180
- expect_identical(n_obs(m2 ), 3570L )
65
+ expect_identical(n_obs(m1 ), 3453L )
181
66
})
182
67
183
68
test_that(" linkfun" , {
@@ -188,21 +73,10 @@ test_that("find_parameters", {
188
73
expect_identical(
189
74
find_parameters(m1 ),
190
75
list (
191
- conditional = c(" lag(union)" , " wks" ),
192
- instruments = c(" (Intercept)" , " imean(lag(union))" , " imean(wks)" , " blk" , " fem" ),
193
- random = " lag(union):blk"
194
- )
195
- )
196
-
197
- expect_identical(nrow(get_parameters(m1 )), 8L )
198
-
199
- expect_identical(
200
- find_parameters(m2 ),
201
- list (
202
- conditional = c(" lag(union)" , " wks" ),
203
- instruments = c(" (Intercept)" , " imean(lag(union))" , " imean(wks)" , " blk" , " t" )
76
+ conditional = c(" (Intercept)" , " +lag(pov)" , " -lag(pov)" , " +spouse" , " -spouse" , " wave" )
204
77
)
205
78
)
79
+ expect_identical(nrow(get_parameters(m1 )), 6L )
206
80
})
207
81
208
82
@@ -211,27 +85,17 @@ test_that("get_parameters", {
211
85
get_parameters(m1 ),
212
86
data.frame (
213
87
Parameter = c(
214
- " lag(union)" ,
215
- " wks" ,
216
- " (Intercept)" ,
217
- " imean(lag(union))" ,
218
- " imean(wks)" ,
219
- " blk" ,
220
- " fem" ,
221
- " lag(union):blk"
88
+ " (Intercept)" , " +lag(pov)" , " -lag(pov)" ,
89
+ " +spouse" , " -spouse" , " wave"
222
90
),
223
91
Estimate = c(
224
- 0.0582474262882615 , - 0.00163678667081885 , 6.59813245629044 ,
225
- - 0.0279959204722801 , 0.00438047648390025 , - 0.229414915661438 ,
226
- - 0.441756913071962 , - 0.127319623945541
227
- ),
228
- Component = c(
229
- " within" , " within" , " between" , " between" ,
230
- " between" , " between" , " between" , " interactions"
92
+ 5.07629091766534 , - 0.695146196282601 , 2.74491742707041 ,
93
+ - 2.99740859292258 , - 0.399625620609947 , - 0.812955475294268
231
94
),
232
95
stringsAsFactors = FALSE
233
96
),
234
- tolerance = 1e-4
97
+ tolerance = 1e-4 ,
98
+ ignore_attr = TRUE
235
99
)
236
100
})
237
101
@@ -240,19 +104,8 @@ test_that("find_terms", {
240
104
expect_identical(
241
105
find_terms(m1 ),
242
106
list (
243
- response = " lwage" ,
244
- conditional = c(" lag(union)" , " wks" ),
245
- instruments = c(" blk" , " fem" ),
246
- interactions = c(" blk" , " lag(union)" )
247
- )
248
- )
249
- expect_identical(
250
- find_terms(m2 ),
251
- list (
252
- response = " lwage" ,
253
- conditional = c(" lag(union)" , " wks" ),
254
- instruments = c(" blk" , " t" ),
255
- random = c(" t" , " id" )
107
+ response = " hours" ,
108
+ conditional = c(" lag(pov)" , " spouse" , " wave" )
256
109
)
257
110
)
258
111
})
@@ -263,12 +116,14 @@ test_that("is_multivariate", {
263
116
264
117
test_that(" find_statistic" , {
265
118
expect_identical(find_statistic(m1 ), " t-statistic" )
266
- expect_identical(find_statistic(m2 ), " t-statistic" )
267
119
})
268
120
269
- test_that(" get_variance " , {
121
+ test_that(" get_vcov " , {
270
122
skip_on_cran()
271
- v <- get_variance(m1 )
272
- expect_equal(v $ var.intercept , c(id = 0.125306895731005 ), tolerance = 1e-4 )
273
- expect_equal(v $ var.fixed , 0.0273792999320531 , tolerance = 1e-4 )
123
+ v <- get_varcov(m1 )
124
+ expect_identical(dim(v ), c(6L , 6L ))
125
+ expect_identical(
126
+ colnames(v ),
127
+ c(" (Intercept)" , " +lag(pov)" , " -lag(pov)" , " +spouse" , " -spouse" , " wave" )
128
+ )
274
129
})
0 commit comments