@@ -4,115 +4,67 @@ test_that("get_parameters, hypothesis_test", {
4
4
data(iris )
5
5
mgg <- lm(Sepal.Width ~ Sepal.Length * Species , data = iris )
6
6
7
- out <- ggeffects :: hypothesis_test(
8
- ggeffects :: ggpredict(mgg , c(" Sepal.Length" , " Species" )),
9
- test = NULL
10
- )
7
+ out <- ggeffects :: test_predictions(mgg , " Sepal.Length" , by = " Species" )
11
8
12
9
param <- get_parameters(out )
13
- expect_named(param , c(" Sepal.Length" , " Species" , " Estimate" ))
14
- expect_identical(
15
- param $ Sepal.Length ,
16
- c(" slope" , " slope" , " slope" )
17
- )
10
+ expect_named(param , c(" Level1" , " Level2" , " Estimate" ))
18
11
expect_identical(
19
- param $ Species ,
20
- structure( 1 : 3 , levels = c(" setosa " , " versicolor" , " virginica" ), class = " factor " )
12
+ as.character( param $ Level1 ) ,
13
+ c(" versicolor" , " virginica" , " virginica " )
21
14
)
22
15
expect_equal(
23
16
param $ Estimate ,
24
- c(0.79853 , 0.31972 , 0.23189 ),
17
+ c(- 0.47881 , - 0.56664 , - 0.08783 ),
25
18
tolerance = 1e-3
26
19
)
27
20
28
21
param <- get_parameters(out , merge_parameters = TRUE )
29
22
expect_named(param , c(" Parameter" , " Estimate" ))
30
23
expect_identical(
31
- param $ Parameter ,
24
+ as.character( param $ Parameter ) ,
32
25
c(
33
- " Sepal.Length [slope ], Species [setosa]" , " Sepal.Length [slope ], Species [versicolor ]" ,
34
- " Sepal.Length [slope ], Species [virginica ]"
26
+ " Level1 [versicolor ], Level2 [setosa]" , " Level1 [virginica ], Level2 [setosa ]" ,
27
+ " Level1 [virginica ], Level2 [versicolor ]"
35
28
)
36
29
)
37
30
expect_equal(
38
31
param $ Estimate ,
39
- c(0.79853 , 0.31972 , 0.23189 ),
32
+ c(- 0.47881 , - 0.56664 , - 0.08783 ),
40
33
tolerance = 1e-3
41
34
)
42
-
43
- out <- ggeffects :: hypothesis_test(ggeffects :: ggpredict(mgg , c(" Sepal.Length" , " Species" )))
44
-
45
- param <- get_parameters(out )
46
- expect_named(param , c(" Sepal.Length" , " Species" , " Estimate" ))
47
- expect_identical(
48
- param $ Sepal.Length ,
49
- c(" slope" , " slope" , " slope" )
50
- )
51
- expect_equal(
52
- param $ Estimate ,
53
- c(0.47881 , 0.56664 , 0.08783 ),
54
- tolerance = 1e-3
55
- )
56
-
57
- param <- get_parameters(out , merge_parameters = TRUE )
58
- expect_named(param , c(" Parameter" , " Estimate" ))
59
35
})
60
36
61
37
62
38
test_that(" get_statistic, hypothesis_test" , {
63
39
data(iris )
64
40
mgg <- lm(Sepal.Width ~ Sepal.Length * Species , data = iris )
65
41
66
- out <- ggeffects :: hypothesis_test(
67
- ggeffects :: ggpredict(mgg , c(" Sepal.Length" , " Species" )),
68
- test = NULL
69
- )
42
+ out <- ggeffects :: hypothesis_test(mgg , " Sepal.Length" , by = " Species" )
70
43
71
44
param <- get_statistic(out )
72
- expect_named(param , c(" Sepal.Length" , " Species" , " Statistic" ))
73
- expect_identical(
74
- param $ Sepal.Length ,
75
- c(" slope" , " slope" , " slope" )
76
- )
77
- expect_identical(
78
- param $ Species ,
79
- structure(1 : 3 , levels = c(" setosa" , " versicolor" , " virginica" ), class = " factor" )
80
- )
45
+ expect_named(param , c(" Level1" , " Level2" , " Statistic" ))
81
46
expect_equal(
82
47
param $ Statistic ,
83
- c(7.23551 , 4.24211 , 3.79015 ),
48
+ c(- 3.58238 , - 4.48999 , - 0.90468 ),
84
49
tolerance = 1e-3
85
50
)
51
+ expect_identical(
52
+ as.character(param $ Level1 ),
53
+ c(" versicolor" , " virginica" , " virginica" )
54
+ )
86
55
87
56
param <- get_statistic(out , merge_parameters = TRUE )
88
57
expect_named(param , c(" Parameter" , " Statistic" ))
89
58
expect_identical(
90
- param $ Parameter ,
59
+ as.character( param $ Parameter ) ,
91
60
c(
92
- " Sepal.Length [slope ], Species [setosa]" , " Sepal.Length [slope ], Species [versicolor ]" ,
93
- " Sepal.Length [slope ], Species [virginica ]"
61
+ " Level1 [versicolor ], Level2 [setosa]" , " Level1 [virginica ], Level2 [setosa ]" ,
62
+ " Level1 [virginica ], Level2 [versicolor ]"
94
63
)
95
64
)
96
65
expect_equal(
97
66
param $ Statistic ,
98
- c(7.23551 , 4.24211 , 3.79015 ),
67
+ c(- 3.58238 , - 4.48999 , - 0.90468 ),
99
68
tolerance = 1e-3
100
69
)
101
-
102
- out <- ggeffects :: hypothesis_test(ggeffects :: ggpredict(mgg , c(" Sepal.Length" , " Species" )))
103
-
104
- param <- get_statistic(out )
105
- expect_named(param , c(" Sepal.Length" , " Species" , " Statistic" ))
106
- expect_identical(
107
- param $ Sepal.Length ,
108
- c(" slope" , " slope" , " slope" )
109
- )
110
- expect_equal(
111
- param $ Statistic ,
112
- c(3.58262 , 4.48915 , 0.90475 ),
113
- tolerance = 1e-3
114
- )
115
-
116
- param <- get_statistic(out , merge_parameters = TRUE )
117
- expect_named(param , c(" Parameter" , " Statistic" ))
118
70
})
0 commit comments