Skip to content

Commit a9ff6a7

Browse files
committed
Missed test file commit
1 parent a315ccf commit a9ff6a7

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

tests/testthat/test_stan_lm.R

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Part of the rstanarm package for estimating model parameters
22
# Copyright (C) 2015, 2016, 2017 Trustees of Columbia University
3-
#
3+
#
44
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU General Public License
66
# as published by the Free Software Foundation; either version 3
77
# of the License, or (at your option) any later version.
8-
#
8+
#
99
# This program is distributed in the hope that it will be useful,
1010
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
# GNU General Public License for more details.
13-
#
13+
#
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program; if not, write to the Free Software
1616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -24,7 +24,7 @@ ITER <- 400
2424
threshold <- 0.21
2525
REFRESH <- 0
2626

27-
SW(fit <- stan_lm(mpg ~ ., data = mtcars, prior = R2(location = 0.75),
27+
SW(fit <- stan_lm(mpg ~ ., data = mtcars, prior = R2(location = 0.75),
2828
chains = CHAINS, iter = ITER, seed = SEED, refresh = 0))
2929

3030

@@ -36,12 +36,12 @@ test_that("stan_aov returns expected result for npk example", {
3636
K = "contr.poly"
3737
)
3838
SW(fit <- stan_aov(yield ~ block + N*P*K, data = npk, contrasts = contrasts_list,
39-
prior = R2(0.5), chains = CHAINS, iter = ITER, seed = SEED,
39+
prior = R2(0.5), chains = CHAINS, iter = ITER, seed = SEED,
4040
refresh = 0))
4141
expect_stanreg(fit)
42-
42+
4343
fit_sigma <- fit$stan_summary["sigma", "mean"]
44-
lm_sigma <- summary(lm(yield ~ block + N*P*K, data = npk,
44+
lm_sigma <- summary(lm(yield ~ block + N*P*K, data = npk,
4545
contrasts = contrasts_list))$sigma
4646
expect_equal(fit_sigma, lm_sigma, tol = threshold)
4747
expect_output(print(fit), regexp = "stan_aov")
@@ -70,27 +70,27 @@ test_that("stan_biglm returns expected result", {
7070
y <- mtcars$mpg
7171
ybar <- mean(y)
7272
s_y <- sd(y)
73-
SW(post <- stan_biglm(biglm, xbar, ybar, s_y, prior = R2(0.5),
73+
SW(post <- stan_biglm(biglm, xbar, ybar, s_y, prior = R2(0.5),
7474
chains = CHAINS, iter = ITER, seed = SEED, refresh = 0))
75-
expect_equal(coef(lm(mpg ~ wt + qsec + am, data = mtcars)),
75+
expect_equal(coef(lm(mpg ~ wt + qsec + am, data = mtcars)),
7676
rstan::summary(post)$summary[1:4, "mean"], tol = threshold)
7777
})
7878

7979
test_that("stan_lm returns expected result for mtcars example", {
8080
# example using mtcars dataset
8181
expect_stanreg(fit)
82-
82+
8383
fit_sigma <- fit$stan_summary["sigma", "mean"]
8484
lm_sigma <- summary(lm(mpg ~ ., data = mtcars))$sigma
8585
expect_equal(fit_sigma, lm_sigma, tol = threshold)
8686
})
8787
test_that("stan_lm returns expected result for trees example", {
8888
# example using trees dataset
89-
SW(fit <- stan_lm(log(Volume) ~ log(Girth) + log(Height), data = trees,
89+
SW(fit <- stan_lm(log(Volume) ~ log(Girth) + log(Height), data = trees,
9090
prior = R2(location = 0.9, what = "mean"), refresh = 0,
9191
chains = CHAINS, iter = ITER, seed = SEED, adapt_delta = 0.999))
9292
expect_stanreg(fit)
93-
93+
9494
fit_sigma <- fit$stan_summary["sigma", "mean"]
9595
lm_sigma <- summary(lm(log(Volume) ~ log(Girth) + log(Height),data = trees))$sigma
9696
expect_equal(fit_sigma, lm_sigma, tol = threshold)
@@ -101,7 +101,7 @@ test_that("stan_lm doesn't break with less common priors", {
101101
SW(fit <- stan_lm(mpg ~ -1 + ., data = mtcars, prior = NULL,
102102
iter = 10, chains = 1, seed = SEED, refresh = 0))
103103
expect_stanreg(fit)
104-
104+
105105
# prior_intercept = normal()
106106
SW(fit <- stan_lm(mpg ~ ., data = mtcars, refresh = 0,
107107
prior = R2(0.75), prior_intercept = normal(),
@@ -110,34 +110,34 @@ test_that("stan_lm doesn't break with less common priors", {
110110
})
111111

112112
test_that("stan_lm doesn't break with vb algorithms", {
113-
SW(fit <- stan_lm(mpg ~ ., data = mtcars,
113+
SW(fit <- stan_lm(mpg ~ ., data = mtcars,
114114
prior = R2(location = 0.75), refresh = 0,
115115
algorithm = "meanfield", seed = SEED))
116116
expect_stanreg(fit)
117-
117+
118118
SW(fit2 <- update(fit, algorithm = "fullrank"))
119119
expect_stanreg(fit2)
120120
})
121121

122122
test_that("stan_lm throws error if only intercept", {
123-
expect_error(stan_lm(mpg ~ 1, data = mtcars, prior = R2(location = 0.75)),
123+
expect_error(stan_lm(mpg ~ 1, data = mtcars, prior = R2(location = 0.75)),
124124
regexp = "not suitable for estimating a mean")
125125
})
126126

127127
test_that("stan_lm throws error if 'location' is a vector", {
128-
expect_error(stan_lm(mpg ~ ., data = mtcars, prior = R2(location = c(0.25, 0.5))),
128+
expect_error(stan_lm(mpg ~ ., data = mtcars, prior = R2(location = c(0.25, 0.5))),
129129
regexp = "only accepts a single value for 'location'")
130130
})
131131

132132
test_that("stan_lm throws error if N < K", {
133133
# NOTE: remove this test once N < K is enabled
134-
expect_error(stan_lm(mpg ~ ., data = mtcars[1:5, ], prior = R2(0.75)),
134+
expect_error(stan_lm(mpg ~ ., data = mtcars[1:5, ], prior = R2(0.75)),
135135
regexp = "more predictors than data points is not yet enabled")
136136
})
137137

138138
test_that("stan_lm throws error if glmer syntax used", {
139-
expect_error(stan_lm(mpg ~ wt + (1|cyl), data = mtcars,
140-
prior = R2(0.5, "mean")),
139+
expect_error(stan_lm(mpg ~ wt + (1|cyl), data = mtcars,
140+
prior = R2(0.5, "mean")),
141141
regexp = "model formula not allowed")
142142
})
143143

@@ -149,6 +149,7 @@ test_that("loo/waic for stan_lm works", {
149149
})
150150

151151
test_that("posterior_predict compatible with stan_lm", {
152+
skip_on_os("mac")
152153
check_for_pp_errors(fit)
153154
expect_linpred_equal(fit)
154155
})

0 commit comments

Comments
 (0)