@@ -6,7 +6,8 @@ library(tibble)
6
6
# ------------------------------------------------------------------------------
7
7
8
8
context(" execution tests for stan logistic regression" )
9
- source(" helper-objects.R" )
9
+ source(test_path(" helper-objects.R" ))
10
+
10
11
11
12
lending_club <- head(lending_club , 200 )
12
13
lc_form <- as.formula(Class ~ log(funded_amnt ) + int_rate )
@@ -106,7 +107,8 @@ test_that('stan_glm probability', {
106
107
107
108
expect_equivalent(
108
109
xy_pred %> % as.data.frame(),
109
- parsnip ::: predict_classprob.model_fit(xy_fit , lending_club [1 : 7 , num_pred ]) %> % as.data.frame()
110
+ parsnip ::: predict_classprob.model_fit(xy_fit , lending_club [1 : 7 , num_pred ]) %> % as.data.frame(),
111
+ tolerance = 0.1
110
112
)
111
113
112
114
res_form <- fit(
@@ -131,7 +133,8 @@ test_that('stan_glm probability', {
131
133
expect_equivalent(
132
134
form_pred %> % as.data.frame(),
133
135
parsnip ::: predict_classprob.model_fit(res_form , lending_club [1 : 7 , c(" funded_amnt" , " int_rate" )]) %> %
134
- as.data.frame()
136
+ as.data.frame(),
137
+ tolerance = 0.1
135
138
)
136
139
})
137
140
@@ -174,11 +177,11 @@ test_that('stan intervals', {
174
177
c(`1` = 0.0181025303127182 , `2` = 0.0388665155739319 , `3` = 0.0205886091162274 ,
175
178
`4` = 0.0181715224502082 , `5` = 0.00405145389896896 )
176
179
177
- expect_equivalent(confidence_parsnip $ .pred_lower_good , stan_lower )
178
- expect_equivalent(confidence_parsnip $ .pred_upper_good , stan_upper )
179
- expect_equivalent(confidence_parsnip $ .pred_lower_bad , 1 - stan_upper )
180
- expect_equivalent(confidence_parsnip $ .pred_upper_bad , 1 - stan_lower )
181
- expect_equivalent(confidence_parsnip $ .std_error , stan_std )
180
+ expect_equivalent(confidence_parsnip $ .pred_lower_good , stan_lower , tolerance = 0.01 )
181
+ expect_equivalent(confidence_parsnip $ .pred_upper_good , stan_upper , tolerance = 0.01 )
182
+ expect_equivalent(confidence_parsnip $ .pred_lower_bad , 1 - stan_upper , tolerance = 0.01 )
183
+ expect_equivalent(confidence_parsnip $ .pred_upper_bad , 1 - stan_lower , tolerance = 0.01 )
184
+ expect_equivalent(confidence_parsnip $ .std_error , stan_std , tolerance = 0.001 )
182
185
183
186
stan_pred_lower <- c(`1` = 0 , `2` = 0 , `3` = 0 , `4` = 0 , `5` = 1 )
184
187
stan_pred_upper <- c(`1` = 1 , `2` = 1 , `3` = 1 , `4` = 1 , `5` = 1 )
0 commit comments