Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Sep 12, 2023
1 parent 67ff198 commit e126aa8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/testthat/tests.make_stancode.R
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ test_that("Stan code for multinomial models is correct", {
prior(normal(0, 2), "Intercept", dpar = muy3)
scode <- make_stancode(bf(y | trials(size) ~ 1, muy2 ~ x), data = dat,
family = multinomial(), prior = prior)
expect_match2(scode, "int Y[N, ncat];")
expect_match2(scode, "array[N, ncat] int Y;")
expect_match2(scode, "target += multinomial_logit2_lpmf(Y[n] | mu[n]);")
expect_match2(scode, "muy2 += Intercept_muy2 + Xc_muy2 * b_muy2;")
expect_match2(scode, "lprior += normal_lpdf(b_muy2 | 0, 10);")
Expand All @@ -681,7 +681,7 @@ test_that("Stan code for dirichlet models is correct", {
prior(exponential(10), "phi")
scode <- make_stancode(bf(y ~ 1, muy3 ~ x), data = dat,
family = dirichlet(), prior = prior)
expect_match2(scode, "vector[ncat] Y[N];")
expect_match2(scode, "array[N] vector[ncat] Y;")
expect_match2(scode, "target += dirichlet_logit_lpdf(Y[n] | mu[n], phi);")
expect_match2(scode, "muy3 += Intercept_muy3 + Xc_muy3 * b_muy3;")
expect_match2(scode, "lprior += normal_lpdf(b_muy3 | 0, 5);")
Expand All @@ -697,7 +697,7 @@ test_that("Stan code for dirichlet models is correct", {
prior <- prior(normal(0, 5), class = "b", dpar = "muy3")
scode <- make_stancode(bf(y ~ 1, muy3 ~ x), data = dat,
family = brmsfamily("dirichlet2"), prior = prior)
expect_match2(scode, "vector[ncat] Y[N];")
expect_match2(scode, "array[N] vector[ncat] Y;")
expect_match2(scode, "muy3 = exp(muy3);")
expect_match2(scode, "target += dirichlet_lpdf(Y[n] | mu[n]);")
expect_match2(scode, "muy3 += Intercept_muy3 + Xc_muy3 * b_muy3;")
Expand All @@ -719,7 +719,7 @@ test_that("Stan code for logistic_normal models is correct", {
scode <- make_stancode(bf(y ~ x), data = dat,
family = logistic_normal(refcat = "y2"),
prior = prior)
expect_match2(scode, "vector[ncat] Y[N];")
expect_match2(scode, "array[N] vector[ncat] Y;")
expect_match2(scode, "mu[n] = transpose([muy1[n], muy3[n]]);")
expect_match2(scode, "vector[ncat-1] sigma = transpose([sigmay1, sigmay3]);")
expect_match2(scode, "target += logistic_normal_cholesky_cor_lpdf(Y[n] | mu[n], sigma, Llncor, 2);")
Expand All @@ -733,7 +733,7 @@ test_that("Stan code for logistic_normal models is correct", {
scode <- make_stancode(bf(y ~ 1, muy3 ~ x, sigmay2 ~ x), data = dat,
family = logistic_normal(),
prior = prior)
expect_match2(scode, "vector[ncat] Y[N];")
expect_match2(scode, "array[N] vector[ncat] Y;")
expect_match2(scode, "mu[n] = transpose([muy2[n], muy3[n]]);")
expect_match2(scode, "sigma[n] = transpose([sigmay2[n], sigmay3]);")
expect_match2(scode, "target += logistic_normal_cholesky_cor_lpdf(Y[n] | mu[n], sigma[n], Llncor, 1);")
Expand Down Expand Up @@ -971,7 +971,7 @@ test_that("grouped ordinal thresholds appear in the Stan code", {
y | thres(th, gr) ~ x, data = dat,
family = sratio(), prior = prior
)
expect_match2(scode, "int<lower=1> nthres[ngrthres];")
expect_match2(scode, "array[ngrthres] int<lower=1> nthres;")
expect_match2(scode, "merged_Intercept[Kthres_start[1]:Kthres_end[1]] = Intercept_1;")
expect_match2(scode, "target += sratio_logit_merged_lpmf(Y[n]")
expect_match2(scode, "lprior += normal_lpdf(Intercept_2 | 0, 1);")
Expand Down Expand Up @@ -1076,7 +1076,7 @@ test_that("monotonic effects appear in the Stan code", {
prior(dirichlet(c(1,0.5,2)), simo, coef = mox11),
prior(dirichlet(c(1,0.5,2)), simo, coef = mox21))
scode <- make_stancode(y ~ y*mo(x1)*mo(x2), dat, prior = prior)
expect_match2(scode, "int Xmo_3[N];")
expect_match2(scode, "array[N] int Xmo_3;")
expect_match2(scode, "simplex[Jmo[1]] simo_1;")
expect_match2(scode, "(bsp[2]) * mo(simo_2, Xmo_2[n])")
expect_match2(scode,
Expand Down Expand Up @@ -1137,7 +1137,7 @@ test_that("Stan code for non-linear models is correct", {
"mu[n] = (nlp_a[n] - exp(nlp_b[n] ^ C_1[n]) * (C_1[n] <= nlp_a[n]) * C_2[n]);"
)
expect_match2(scode, "vector[N] C_1;")
expect_match2(scode, "int C_2[N];")
expect_match2(scode, "array[N] int C_2;")

# non-linear predictor can be computed outside a loop
scode <- make_stancode(bf(y ~ a - exp(b + z), flist = flist,
Expand Down Expand Up @@ -1224,7 +1224,7 @@ test_that("make_stancode is correct for non-linear matrix covariates", {
nlstanvar <- stanvar(scode = nlfun_stan_int, block = "functions")
bform <- bf(y~nlfun(a, b, c, X2), a~1, b~1, c~1, nl = TRUE)
scode <- make_stancode(bform, dat, stanvars = nlstanvar)
expect_match2(scode, "int C_1[N, 2];")
expect_match2(scode, "array[N, 2] int C_1;")
})

test_that("make_stancode accepts very long non-linear formulas", {
Expand Down

0 comments on commit e126aa8

Please sign in to comment.