Skip to content

Commit 2fe0715

Browse files
committed
fixes
1 parent bd0b0f9 commit 2fe0715

File tree

2 files changed

+30
-175
lines changed

2 files changed

+30
-175
lines changed

R/get_varcov.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ get_varcov.fixest <- function(x,
138138
get_varcov.asym <- function(x, ...) {
139139
out <- get_varcov.default(x, ...)
140140
colnames(out) <- gsub("^plus__", "+", colnames(out))
141-
rownames(out) <- gsub("^plus__", "+", rownames(out))
141+
rownames(out) <- gsub("^minus__", "-", rownames(out))
142142
out
143143
}
144144

tests/testthat/test-panelr-asym.R

Lines changed: 29 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
skip_if_not_installed("panelr")
2+
skip_if_not_installed("clubSandwich")
3+
skip_if_not_installed("car")
24

35
data("teen_poverty", package = "panelr")
46
teen <- panelr::long_panel(teen_poverty, begin = 1, end = 5)
@@ -9,138 +11,38 @@ test_that("model_info", {
911
})
1012

1113
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))
1415
})
1516

1617
test_that("find_predictors", {
1718
expect_identical(
1819
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"))
2421
)
2522
expect_identical(
2623
find_predictors(m1, flatten = TRUE),
27-
c("union", "wks", "blk", "fem")
24+
c("pov", "spouse", "wave")
2825
)
2926
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"))
3927
})
4028

4129
test_that("find_random", {
4230
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)
4931
})
5032

5133
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")
6835
})
6936

7037
test_that("link_inverse", {
7138
expect_equal(link_inverse(m1)(0.2), 0.2, tolerance = 1e-5)
7239
})
7340

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-
12541
test_that("find_formula", {
126-
expect_length(find_formula(m1), 3)
42+
expect_length(find_formula(m1), 1)
12743
expect_equal(
12844
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")),
14446
ignore_attr = TRUE
14547
)
14648
})
@@ -149,35 +51,18 @@ test_that("find_variables", {
14951
expect_identical(
15052
find_variables(m1),
15153
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")
15656
)
15757
)
15858
expect_identical(
15959
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")
17561
)
17662
})
17763

17864
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)
18166
})
18267

18368
test_that("linkfun", {
@@ -188,21 +73,10 @@ test_that("find_parameters", {
18873
expect_identical(
18974
find_parameters(m1),
19075
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")
20477
)
20578
)
79+
expect_identical(nrow(get_parameters(m1)), 6L)
20680
})
20781

20882

@@ -211,27 +85,17 @@ test_that("get_parameters", {
21185
get_parameters(m1),
21286
data.frame(
21387
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"
22290
),
22391
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
23194
),
23295
stringsAsFactors = FALSE
23396
),
234-
tolerance = 1e-4
97+
tolerance = 1e-4,
98+
ignore_attr = TRUE
23599
)
236100
})
237101

@@ -240,19 +104,8 @@ test_that("find_terms", {
240104
expect_identical(
241105
find_terms(m1),
242106
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")
256109
)
257110
)
258111
})
@@ -263,12 +116,14 @@ test_that("is_multivariate", {
263116

264117
test_that("find_statistic", {
265118
expect_identical(find_statistic(m1), "t-statistic")
266-
expect_identical(find_statistic(m2), "t-statistic")
267119
})
268120

269-
test_that("get_variance", {
121+
test_that("get_vcov", {
270122
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+
)
274129
})

0 commit comments

Comments
 (0)