From 46632b42fb438dd55d0e9da9f5ca13614cd771aa Mon Sep 17 00:00:00 2001 From: Marko Lalovic Date: Fri, 21 Jun 2024 11:29:39 +0200 Subject: [PATCH] response_prop added to tests --- dev/dev.R | 1 - man/simulate_likert.Rd | 6 +++--- tests/testthat/test_simulation.R | 12 +++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dev/dev.R b/dev/dev.R index 16c3210..7d62418 100644 --- a/dev/dev.R +++ b/dev/dev.R @@ -1,3 +1,2 @@ # Development devtools::load_all("/Users/markolalovic/dev/latent2likert/") - diff --git a/man/simulate_likert.Rd b/man/simulate_likert.Rd index e6d5613..daa4ad8 100644 --- a/man/simulate_likert.Rd +++ b/man/simulate_likert.Rd @@ -21,7 +21,7 @@ Simulates Likert scale item responses based on a specified number of response categories and the centered parameters of the latent variable. } \details{ -The simulation process uses the following model proposed by Boari and Nai-Ruscone. +The simulation process uses the following model detailed by Boari and Nai-Ruscone. Let \eqn{X} be the continuous variable of interest, measured using Likert scale questions with \eqn{K} response categories. The observed discrete variable \eqn{Y} is defined as follows: @@ -58,8 +58,8 @@ simulate_likert(n_levels = 7, cp = cp2) } \references{ Boari, G. and Nai Ruscone, M. (2015). -A procedure simulating likert scale item responses. -\emph{Electronic journal of applied statistical analysis} \bold{8(3)}, 288–297. +A procedure simulating Likert scale item responses. +\emph{Electronic Journal of Applied Statistical Analysis} \bold{8(3)}, 288–297. \doi{10.1285/i20705948v8n3p288} } \seealso{ diff --git a/tests/testthat/test_simulation.R b/tests/testthat/test_simulation.R index cb3ae1b..03c16ce 100644 --- a/tests/testthat/test_simulation.R +++ b/tests/testthat/test_simulation.R @@ -5,7 +5,7 @@ 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 @@ -13,9 +13,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) } }) @@ -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) } })