Skip to content

Commit

Permalink
response_prop added to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markolalovic committed Jun 21, 2024
1 parent 8729418 commit 46632b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion dev/dev.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Development
devtools::load_all("/Users/markolalovic/dev/latent2likert/")

6 changes: 3 additions & 3 deletions man/simulate_likert.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions tests/testthat/test_simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ testthat::test_that("proportions of generated responses match actual probabiliti
n_levels <- 5
n_items <- 3

mean <- c(0, -1, -1)
mean <- c(-1, 0, 1)
sd <- c(1, 1, 0.5)
skew <- c(0.5, 0.5, 0.5)
corr <- 0.5

data <- rlikert(size, n_items, n_levels, mean, sd, skew, corr)
for (i in seq_len(n_items)) {
cp <- c("mu"=mean[i], "sd"=sd[i], "skew"=skew[i])
prob <- simulate_likert(5, cp)
prob <- as.numeric(prob)
data_prop <- as.numeric(prop.table(table(data[,i])))
prob <- simulate_likert(n_levels, cp)
data_prop <- response_prop(data[,i], n_levels)
testthat::expect_equal(prob, data_prop, tolerance = 0.05)
}
})
Expand All @@ -34,9 +33,8 @@ testthat::test_that("proportions of generated responses match actual probabiliti
data <- rlikert(size, n_items, n_levels, mean, sd, skew, corr)
for (i in seq_len(n_items)) {
cp <- c("mu"=mean[i], "sd"=sd[i], "skew"=skew[i])
prob <- simulate_likert(5, cp)
prob <- as.numeric(prob)
data_prop <- as.numeric(prop.table(table(data[,i])))
prob <- simulate_likert(n_levels, cp)
data_prop <- response_prop(data[,i], n_levels)
testthat::expect_equal(prob, data_prop, tolerance = 0.05)
}
})
Expand Down

0 comments on commit 46632b4

Please sign in to comment.