-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,4 @@ plot_fixefs.merMod <- function(model, | |
} | ||
} | ||
|
||
# plot_fixefs.glmerMod <- plot_fixefs.merMod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
load('brms_res.RData') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
context('test coefficient plots') | ||
|
||
|
||
test_lm = lm(mpg ~ ., mtcars) | ||
|
||
x = rnorm(100) | ||
q = rnorm(100) | ||
z = rnorm(100) | ||
y = rpois(100, exp(.25*x + .1*q - .5*z)) | ||
test_glm = glm(y ~ x + q + z, family = poisson) | ||
|
||
fit_mer = lme4::lmer(Reaction ~ Days + (Days|Subject), lme4::sleepstudy) | ||
fit_mer2 = lme4::lmer(count ~ log_Age_c + log_Base4_c * Trt + (1 | patient), brms::epilepsy) | ||
mer_re = plot_coefficients(fit_mer, ranef = T, which_ranef = 'Subject') | ||
|
||
test_that('It works', { | ||
expect_s3_class(mer_re[[1]], 'ggplot') | ||
}) | ||
|
||
test_that('It works', { | ||
expect_s3_class(plot_coefficients(test_lm, plot = FALSE), 'data.frame') | ||
}) | ||
|
||
|
||
|
||
# test lm glm coefficients ------------------------------------------------ | ||
|
||
test_that('test plot_coefficients.lm', { | ||
expect_s3_class(plot_coefficients(test_lm), 'ggplot') | ||
}) | ||
|
||
test_that('test palette', { | ||
expect_s3_class(plot_coefficients(test_lm, palette = 'oslo'), 'ggplot') | ||
}) | ||
|
||
test_that('test order numeric', { | ||
expect_s3_class(plot_coefficients(test_lm, order = sample(1:10)), 'ggplot') | ||
}) | ||
|
||
test_that('test order increasing', { | ||
expect_s3_class(plot_coefficients(test_lm, order = 'increasing'), 'ggplot') | ||
}) | ||
|
||
|
||
test_that('test plot_coefficients.glm and trans', { | ||
expect_s3_class(plot_coefficients(test_glm, trans = exp, ref_line = 1), 'ggplot') | ||
}) | ||
|
||
|
||
|
||
|
||
|
||
# test lme4 --------------------------------------------------------------- | ||
|
||
# test fixed effects plots ------------------------------------------------ | ||
test_that('test fixef options', { | ||
test_fe = plot_coefficients(fit_mer, ranef = F) | ||
expect_s3_class(test_fe, 'ggplot') | ||
}) | ||
|
||
test_that('test fixef options order increasing', { | ||
test_fe = plot_coefficients(fit_mer, order = 'increasing') | ||
expect_s3_class(test_fe, 'ggplot') | ||
}) | ||
|
||
test_that('test fixef options order numeric', { | ||
test_fe = plot_coefficients(fit_mer2, order = 4:1) | ||
expect_s3_class(test_fe, 'ggplot') | ||
}) | ||
|
||
test_that('no plot works', { | ||
expect_s3_class(plot_coefficients(fit_mer, plot = FALSE), 'data.frame') | ||
}) | ||
|
||
|
||
# test random effect plots ------------------------------------------------ | ||
|
||
test_that('test ranef options', { | ||
expect_s3_class(mer_re[[1]], 'ggplot') | ||
}) | ||
|
||
test_that('test error with wrong ranef', { | ||
expect_error(plot_coefficients(fit_mer, ranef = T, which_ranef = 'blah')) | ||
}) | ||
|
||
test_that('test error with null ranef', { | ||
expect_error(plot_coefficients(fit_mer, ranef = T, which_ranef = NULL)) | ||
}) | ||
|
||
test_that('test can return data', { | ||
expect_s3_class(plot_coefficients(fit_mer, ranef = T, which_ranef = 'Subject', plot=F)[[1]], 'data.frame') | ||
}) | ||
|
||
# test brms --------------------------------------------------------------- | ||
|
||
|
||
# test fixed effects plots ------------------------------------------------ | ||
|
||
test_that('test fixef options', { | ||
test_fe = plot_coefficients(fit1, ranef = F) | ||
expect_s3_class(test_fe, 'ggplot') | ||
}) | ||
|
||
test_that('test fixef options order increasing', { | ||
test_fe = plot_coefficients(fit1, order = 'increasing') | ||
expect_s3_class(test_fe, 'ggplot') | ||
}) | ||
|
||
test_that('test fixef options order numeric', { | ||
test_fe = plot_coefficients(fit1, order = 4:1) | ||
expect_s3_class(test_fe, 'ggplot') | ||
}) | ||
|
||
test_that('no plot works', { | ||
expect_s3_class(plot_coefficients(fit1, plot = FALSE), 'data.frame') | ||
}) | ||
|
||
|
||
# test random effect plots ------------------------------------------------ | ||
|
||
|
||
test_that('test ranef options', { | ||
expect_s3_class(plot_coefficients(fit1, ranef = T, which_ranef='patient')[[1]], 'ggplot') | ||
}) | ||
|
||
test_that('test error with wrong ranef', { | ||
expect_error(plot_coefficients(fit1, ranef = T, which_ranef = 'blah')) | ||
}) | ||
|
||
test_that('test error with null ranef', { | ||
expect_error(plot_coefficients(fit1, ranef = T, which_ranef = NULL)) | ||
}) | ||
|
||
test_that('test can return data', { | ||
expect_s3_class(plot_coefficients(fit1, ranef = T, which_ranef = 'patient', plot=F)[[1]], 'data.frame') | ||
}) |