diff --git a/.Rbuildignore b/.Rbuildignore index 9a49f19..5ffc235 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,6 +1,5 @@ ^.*\.Rproj$ ^\.Rproj\.user$ -^NEWS\.md$ ^README\.md$ ^dev\.R$ ^\.travis\.yml$ @@ -10,3 +9,5 @@ gendat3* .vscode ^Meta$ ^doc$ +^\.github$ +^CRAN-SUBMISSION$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..596732b --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [master, develop, release-*] + pull_request: + branches: [develop] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml new file mode 100644 index 0000000..74ec7b0 --- /dev/null +++ b/.github/workflows/rhub.yaml @@ -0,0 +1,95 @@ +# R-hub's generic GitHub Actions workflow file. It's canonical location is at +# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml +# You can update this file to a newer version using the rhub2 package: +# +# rhub::rhub_setup() +# +# It is unlikely that you need to modify this file manually. + +name: R-hub +run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" + +on: + workflow_dispatch: + inputs: + config: + description: 'A comma separated list of R-hub platforms to use.' + type: string + default: 'linux,windows,macos' + name: + description: 'Run name. You can leave this empty now.' + type: string + id: + description: 'Unique ID. You can leave this empty now.' + type: string + +jobs: + + setup: + runs-on: ubuntu-latest + outputs: + containers: ${{ steps.rhub-setup.outputs.containers }} + platforms: ${{ steps.rhub-setup.outputs.platforms }} + + steps: + # NO NEED TO CHECKOUT HERE + - uses: r-hub/actions/setup@v1 + with: + config: ${{ github.event.inputs.config }} + id: rhub-setup + + linux-containers: + needs: setup + if: ${{ needs.setup.outputs.containers != '[]' }} + runs-on: ubuntu-latest + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.containers) }} + container: + image: ${{ matrix.config.container }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/run-check@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + + other-platforms: + needs: setup + if: ${{ needs.setup.outputs.platforms != '[]' }} + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.platforms) }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/setup-r@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/run-check@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 86f8e6f..0d5c988 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +CRAN-SUBMISSION + #--------------------------# #--- The usual suspects ---# #--------------------------# diff --git a/DESCRIPTION b/DESCRIPTION index a5aa244..f6cf873 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: lsasim Title: Functions to Facilitate the Simulation of Large Scale Assessment Data -Version: 2.1.4 +Version: 2.1.5 Authors@R: c( person("Tyler", "Matta", email = "tyler.matta@gmail.com", role = "aut"), @@ -30,11 +30,12 @@ Depends: License: GPL-3 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Suggests: testthat, knitr, formatR, - rmarkdown + rmarkdown, + NAEPirtparams VignetteBuilder: knitr -Date: 2023-08-21 +Date: 2024-05-06 diff --git a/NEWS.md b/NEWS.md index 12b98fd..7282bbe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,62 +1,62 @@ -lsasim 2.1.4 ------------- +# lsasim 2.1.5 -### Bug fixes +## Bug fixes + +* Fixed `block_design()` for non-sequential items (issue #50) +* Fixed typos in documentation +* Reimplemented continuous integration routine (issue #47) + +# lsasim 2.1.4 + +## Bug fixes * Fixed top-level package documentation (`?lsasim`) -lsasim 2.1.3 ------------- +# lsasim 2.1.3 -### Bug fixes +## Bug fixes * Fixes generation of thresholds on `item_gen()` (issue #48) * Refactored usage of `class()` on if-statements -lsasim 2.1.2 ------------- +# lsasim 2.1.2 -### Bug fixes +## Bug fixes * Refactoring to fix building on Fedora/Clang and M1-powered Macs -lsasim 2.1.1 ------------- +# lsasim 2.1.1 -### Bug fixes +## Bug fixes * Fixes test unit dependency on GNU libiconv -lsasim 2.1.0 ------------- +# lsasim 2.1.0 -### API changes +## API changes * Adds `cluster_gen`, a function to generate background questionnaires (with `questionnaire_gen`) in a cluster sampling structure. * Package description now includes a literary reference for the theoretical framework behind the package (issue #38, pull request #42) -### Bug fixes +## Bug fixes -* Fixes item parameter generation by `irt_gen` when the guesssing parameter is larger than zero (issue #40) +* Fixes item parameter generation by `irt_gen` when the guessing parameter is larger than zero (issue #40) -lsasim 2.0.2 ------------- +# lsasim 2.0.2 -### Bug fixes +## Bug fixes * Solves [Issue #11](https://github.com/tmatta/lsasim/issues/11), which was causing `item_gen()` to produce out-of-bounds item difficulties in some situations. -lsasim 2.0.1 ------------- +# lsasim 2.0.1 -### Bug fixes +## Bug fixes -* Makes lsasim compliant with changes to be introduced in the next major release of R. lsasim 2.0.1 is functionally identical to 2.0.0, as all changes relate to how `if (class(x) == "matrix"` statements are written. Specifically, such statements were changed to `if(class(x))[1] == "matrix"` to accomodate for cases where `x` may be a matrix with complex classes such as `"matrix" "array"`. +* Makes lsasim compliant with changes to be introduced in the next major release of R. lsasim 2.0.1 is functionally identical to 2.0.0, as all changes relate to how `if (class(x) == "matrix"` statements are written. Specifically, such statements were changed to `if(class(x))[1] == "matrix"` to accommodate for cases where `x` may be a matrix with complex classes such as `"matrix" "array"`. -lsasim 2.0.0 ------------- +# lsasim 2.0.0 -### API changes +## API changes This release adds several features to the `questionnaire_gen` function, such as: @@ -69,25 +69,22 @@ Please read the function's help file for more details on how to access these new *Note*: any R code written for the `questionnaire_gen` function from previous versions of lsasim may not work properly on this version due to the rearrangement of the function's arguments and slight changes in its default behavior. Please review your code before executing old scripts. -lsasim 1.0.1 -------------- +# lsasim 1.0.1 -### API changes +## API changes * Added `cov_bounds` to `cor_gen`. * Removed `d1` from the returned data frame of `item_gen` when `thresholds = 1`. -lsasim 1.0.1.9000 -------------- +# lsasim 1.0.1.9000 -### API changes +## API changes * Added `item_no` to `response_gen`. -### Bug fixes +## Bug fixes * `response_gen` can now handle item subsets. -lsasim 1.0.0 -------------- +# lsasim 1.0.0 * Launched diff --git a/R/anova.R b/R/anova.R index fc0f5fc..5c19a03 100644 --- a/R/anova.R +++ b/R/anova.R @@ -2,7 +2,7 @@ #' @description Prints Analysis of Variance table for `cluster_gen` output. #' @param object list output of `cluster_gen` #' @param print if `TRUE`, output will be a list containing estimators; if `FALSE` (default), output are formatted tables of this information -#' @param calc.se if `TRUE`, will try to calculate the standard error of the intreaclass correlation +#' @param calc.se if `TRUE`, will try to calculate the standard error of the intraclass correlation #' @param ... additional objects of the same type (see `help("anova")` for details) #' @return Printed ANOVA table or list of parameters #' @note If the rhos for different levels are varied in scale, the generated rho will be less accurate. diff --git a/R/beta_gen.R b/R/beta_gen.R index e43343c..724089b 100644 --- a/R/beta_gen.R +++ b/R/beta_gen.R @@ -16,7 +16,7 @@ #' "q" #' @param verbose if `FALSE`, output messages will be suppressed (useful for simulations). Defaults to `TRUE` #' @importFrom stats lm model.matrix quantile cov pnorm setNames -#' @details This function was primarily conceived as a subfunction of +#' @details This function was primarily conceived as a sub-function of #' \code{questionnaire_gen}, when \code{family = "gaussian"}, \code{theta = #' TRUE}, and \code{full_output = TRUE}. However, it can also be directly #' called by the user so they can perform further analysis. diff --git a/R/block_design.R b/R/block_design.R index b90f57d..b24d64c 100644 --- a/R/block_design.R +++ b/R/block_design.R @@ -1,27 +1,27 @@ #' Assignment of test items to blocks #' -#' \code{block_design} creates a length-2 list containing: +#' \code{block_design} creates a length-2 list containing: #' \itemize{ #' \item a matrix that identifies which items correspond to which blocks and -#' \item a table of block descriptive statisics. +#' \item a table of block descriptive statistics. #'} -#' +#' #' @param n_blocks an integer indicating how many blocks to create. #' @param item_parameters a data frame of item parameters. #' @param item_block_matrix a matrix of indicators to assign items to blocks. -#' +#' #' @section Warning: -#' The default \code{item_block_matrix} spirals the items across the \code{n_blocks} and requires \code{n_blocks} >= 3. +#' The default \code{item_block_matrix} spirals the items across the \code{n_blocks} and requires \code{n_blocks} >= 3. #' If \code{n_blocks} < 3, \code{item_block_matrix} must be specified. -#' +#' #' The columns of \code{item_block_matrix} represent each block while the rows #' represent the total number of items. \code{item_block_matrix[1, 1] = 1} indicates #' that block 1 contains item 1 while \code{item_block_matrix[1, 2] = 0} indicates that #' block 2 does not contain item 1. -#' +#' #' @examples #' item_param <- data.frame(item = seq(1:25), b = runif(25, -2, 2)) -#' ib_matrix <- matrix(nrow = 25, ncol = 5, byrow = FALSE, +#' ib_matrix <- matrix(nrow = 25, ncol = 5, byrow = FALSE, #' c(1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, #' 0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, #' 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, @@ -29,9 +29,15 @@ #' 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1)) #' block_design(n_blocks = 5, item_parameters = item_param, item_block_matrix = ib_matrix) #' block_design(n_blocks = 5, item_parameters = item_param) -#' +#' #' @export block_design <- function(n_blocks = NULL, item_parameters, item_block_matrix = NULL){ + # Validation of input + if (is.null(item_parameters[["item"]])) { + stop("item_parameters must contain an 'item' column.") + } else if (any(duplicated(item_parameters[["item"]]))) { + stop("item_parameters must contain unique 'item' values.") + } if (is.null(n_blocks)) n_blocks <- ncol(item_block_matrix) n_items <- nrow(item_parameters) @@ -41,19 +47,19 @@ block_design <- function(n_blocks = NULL, item_parameters, item_block_matrix = N item_block_vec <- rep(1:n_blocks, length.out = n_items) item_no <- rep(1:n_items) item_block_matrix <- matrix(NA, nrow = n_items, ncol = n_blocks) - + for(j in 1:n_blocks){ for(i in 1:n_items){ item_block_matrix[i, j] <- ifelse(item_block_vec[i] == j, 1, 0) } } } - + block_vec <- paste0("b", 1:n_blocks) colnames(item_block_matrix) <- block_vec item_block_df <- data.frame(item_block_matrix) - item_block_df$item <- rownames(item_block_df) + item_block_df$item <- item_parameters[["item"]] block_assignment <- merge(item_parameters, item_block_df, by = "item") #--- Build block descriptives table diff --git a/R/booklet_design.R b/R/booklet_design.R index ef0d16d..c856c09 100644 --- a/R/booklet_design.R +++ b/R/booklet_design.R @@ -1,35 +1,35 @@ #' Assignment of item blocks to test booklets #' #' \code{block_design} creates a data frame that identifies which items corresponds to which booklets. -#' -#' @param item_block_assignment a matrix that identifies which items correspond to which block. -#' @param book_design a matrix of indicators to assign blocks to booklets. -#' +#' +#' @param item_block_assignment a matrix that identifies which items correspond to which block. +#' @param book_design a matrix of indicators to assign blocks to booklets. +#' #' @section Details: #' If using \code{booklet_design} in tandem with \code{block_design}, \code{item_block_assignment} #' is the the first element of the returned list of \code{block_design}. -#' +#' #' The columns of \code{item_block_assignment} represent each block while the rows -#' represent the number of items in each block. Becuase the number of items per -#' block can vary, the number of rows represents the block with the most items. The -#' contets of \code{item_block_assignment} is the actual item numbers. The remainer of -#' shorter blocks are filled with zeros. -#' +#' represent the number of items in each block. Because the number of items per +#' block can vary, the number of rows represents the block with the most items. The +#' contents of \code{item_block_assignment} is the actual item numbers. The remainder of +#' shorter blocks are filled with zeros. +#' #' The columns of \code{book_design} represent each book while the rows #' represent each block. -#' +#' #' The default \code{book_design} assigns two blocks to every booklet in a spiral design. -#' The number of default booklets is equal to the number of blocks and must be >= 3. +#' The number of default booklets is equal to the number of blocks and must be >= 3. #' If \code{ncol(item_block_assignment)} < 3, \code{book_design} must be specified. -#' +#' #' @examples -#' i_blk_mat <- matrix(seq(1:40), ncol = 5) +#' i_blk_mat <- matrix(seq(1:40), ncol = 5) #' blk_book <- matrix(c(1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, -#' 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0), +#' 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0), #' ncol = 5, byrow = TRUE) #' booklet_design(item_block_assignment = i_blk_mat, book_design = blk_book) #' booklet_design(item_block_assignment = i_blk_mat) -#' +#' #' @export booklet_design <- function(item_block_assignment, book_design = NULL){ @@ -58,12 +58,12 @@ booklet_design <- function(item_block_assignment, book_design = NULL){ } } book_design <- book_block_mat - } + } #--- number of book is determined by the user specified book design if (!is.null(book_design)) n_book <- nrow(book_design) - + #--- Assign items to booklets max_items_per_book <- max(rowSums(book_design)) * max_items @@ -78,7 +78,7 @@ booklet_design <- function(item_block_assignment, book_design = NULL){ } else if (nrow(item_matrix) - length(book_k_items) == 0) { zero_fill <- NULL } - book_k <- c(book_k_items, zero_fill) + book_k <- c(book_k_items, zero_fill) item_matrix[, k] <- book_k } @@ -96,4 +96,4 @@ booklet_design <- function(item_block_assignment, book_design = NULL){ booklet <- data.frame(item_matrix) return(booklet) -} \ No newline at end of file +} diff --git a/R/brr.R b/R/brr.R index 71cdf98..73af99c 100644 --- a/R/brr.R +++ b/R/brr.R @@ -10,9 +10,9 @@ #' @return a list containing all the BRR replicates of `data` #' @seealso jackknife #' @note PISA uses the BRR Fay method with \eqn{k = 0.5}. -#' @references +#' @references #' OECD (2015). Pisa Data Analysis Manual. -#' Adams, R., & Wu, M. (2002). PISA 2000 Technical Report. Paris: Organisation for Economic Co-operation and Development (OECD). +#' Adams, R., & Wu, M. (2002). PISA 2000 Technical Report. Paris: Organization for Economic Co-operation and Development (OECD). #' Rust, K. F., & Rao, J. N. K. (1996). Variance estimation for complex surveys using replication techniques. Statistical methods in medical research, 5(3), 283-310. #' @export brr <- function(data, k = 0, pseudo_strata = ceiling(nrow(data) / 2), @@ -44,7 +44,7 @@ brr <- function(data, k = 0, pseudo_strata = ceiling(nrow(data) / 2), } # Determining the number of replicates ===================================== - if (is.null(reps)) { + if (is.null(reps)) { total_replicates <- 4 for (r in seq_len(pseudo_strata)) { if (r %% 4 == 0) total_replicates <- total_replicates + 4 @@ -63,7 +63,7 @@ brr <- function(data, k = 0, pseudo_strata = ceiling(nrow(data) / 2), if (pseudo_strata == 0) { data$pseudo_stratum <- 1 pseudo_strata <- 1 - } else { + } else { expanded_pseudo_strata <- rep(seq_len(pseudo_strata), each = 2) data$pseudo_stratum <- c(expanded_pseudo_strata, pseudo_strata) } @@ -105,4 +105,4 @@ brr <- function(data, k = 0, pseudo_strata = ceiling(nrow(data) / 2), replicate -> R[[paste0("R", rep)]] } return(R) -} \ No newline at end of file +} diff --git a/R/calc_replicate_weights.R b/R/calc_replicate_weights.R index 7fac1a3..470b1e4 100644 --- a/R/calc_replicate_weights.R +++ b/R/calc_replicate_weights.R @@ -9,7 +9,7 @@ #' @references #' OECD (2015). Pisa Data Analysis Manual. #' Rust, K. F., & Rao, J. N. K. (1996). Variance estimation for complex surveys using replication techniques. Statistical methods in medical research, 5(3), 283-310. -#' @return list with data and, if requeted, some statistics +#' @return list with data and, if requested, some statistics #' @note This function is essentially a big wrapper for `replicate_var`, applying that function on each element of an output of `cluster_gen`. #' @examples #' data <- cluster_gen(c(3, 50)) @@ -76,4 +76,4 @@ calc_replicate_weights <- function(data, method, k = 0) { # Assembling output ======================================================== out <- replicate_stats return(out) -} \ No newline at end of file +} diff --git a/R/cluster_gen.R b/R/cluster_gen.R index 56eeb28..0749bcc 100644 --- a/R/cluster_gen.R +++ b/R/cluster_gen.R @@ -23,14 +23,14 @@ #' @param print_pop_structure if `TRUE`, prints the population hierarchical structure (as long as it differs from the sample structure) #' @param ... Additional parameters to be passed to `questionnaire_gen()` #' @return list with background questionnaire data, grouped by level or not -#' @details This function relies heavily in two subfunctions---`cluster_gen_separate` and `cluster_gen_together`---which can be called independently. This does not make `cluster_gen` a simple wrapper function, as it performs several operations prior to calling its subfunctions, such as randomly generating `n_X` and `n_W` if they are not determined by user. +#' @details This function relies heavily in two sub-functions---`cluster_gen_separate` and `cluster_gen_together`---which can be called independently. This does not make `cluster_gen` a simple wrapper function, as it performs several operations prior to calling its sub-functions, such as randomly generating `n_X` and `n_W` if they are not determined by user. #' `n` can have unitary length, in which case all clusters will have the same size. #' `N` is *not* the population size across all elements of a level, but the population size for each element of one level. #' Regarding the additional parameters to be passed to `questionnaire_gen()`, they can be passed either in the same format as `questionnaire_gen()` or as more complex objects that contain information for each cluster level. #' #' @note For the purpose of this function, levels are counted starting from the top nesting/clustering level. This means that, for example, schools are the first cluster level, classes are the second, and students are the third and final level. This behavior can be customized by naming the `n` argument or providing custom labels in `cluster_labels` and `resp_labels`. #' -#' @note Manually setting both `c_mean` and `rho`, while possible, may yield unexpected results due to how those parameters work together. A high intraclass correlation (`rho`) teoretically means that each group will end up with different means so they can be better separated. If `c_mean` is left untouched (i.e., at the default value of zero), then `c_mean` will freely change between clusters in order to result in the expected intraclass correlation. For large samples, `c_mean` will in practice correspond to the grand mean across that level, as the means of each element will be different no matter the sample size. +#' @note Manually setting both `c_mean` and `rho`, while possible, may yield unexpected results due to how those parameters work together. A high intraclass correlation (`rho`) theoretically means that each group will end up with different means so they can be better separated. If `c_mean` is left untouched (i.e., at the default value of zero), then `c_mean` will freely change between clusters in order to result in the expected intraclass correlation. For large samples, `c_mean` will in practice correspond to the grand mean across that level, as the means of each element will be different no matter the sample size. #' #' Moreover, if `c_mean`, `sigma` and `rho` are passed to the function, the means will be recalculated as a function of the other two parameters. The three are interdependent and cannot be passed simultaneously. #' diff --git a/R/cluster_gen_separate.R b/R/cluster_gen_separate.R index d8b5759..a1d134b 100644 --- a/R/cluster_gen_separate.R +++ b/R/cluster_gen_separate.R @@ -1,5 +1,5 @@ #' @title Generate cluster samples with individual questionnaires -#' @description This is a subfunction of `cluster_gen` that performs cluster sampling, with the twist that each cluster level has its own questionnaire. +#' @description This is a sub-function of `cluster_gen` that performs cluster sampling, with the twist that each cluster level has its own questionnaire. #' @param n_levels number of cluster levels #' @param n numeric vector with the number of sampled observations (clusters or subjects) on each level #' @param cluster_labels character vector with the names of each cluster level diff --git a/R/cluster_gen_together.R b/R/cluster_gen_together.R index 65dfbdf..5d73704 100644 --- a/R/cluster_gen_together.R +++ b/R/cluster_gen_together.R @@ -1,5 +1,5 @@ #' @title Generate cluster samples with lowest-level questionnaires -#' @description This is a subfunction of `cluster_gen` that performs cluster sampling where only the lowest-level individuals (e.g. students) fill out questionnaires. +#' @description This is a sub-function of `cluster_gen` that performs cluster sampling where only the lowest-level individuals (e.g. students) fill out questionnaires. #' @param n_levels number of cluster levels #' @param n numeric vector with the number of sampled observations (clusters or subjects) on each level #' @param cluster_labels character vector with the names of each cluster level diff --git a/R/irt_gen.R b/R/irt_gen.R index 040e714..c589e29 100644 --- a/R/irt_gen.R +++ b/R/irt_gen.R @@ -6,7 +6,7 @@ #' @param b_par numeric or vector of numerics difficulty parameter(s). #' @param a_par numeric discrimination parameter. #' @param c_par numeric guessing parameter. -#' @param D numeric parameter to specify logisitic (1) or normal (1.7). +#' @param D numeric parameter to specify logistic (1) or normal (1.7). #' #' @examples #' irt_gen(theta = 0.2, b_par = 0.6) @@ -23,5 +23,3 @@ irt_gen <- function(theta, a_par = 1, b_par, c_par = 0, D = 1) { y <- sample(1:length(response_pr) - 1, size = 1, prob = response_pr) return(y) } - - diff --git a/R/pisa2012_q_cormat.R b/R/pisa2012_q_cormat.R index 7bb7328..dcffdb0 100644 --- a/R/pisa2012_q_cormat.R +++ b/R/pisa2012_q_cormat.R @@ -1,45 +1,45 @@ #' Correlation matrix from the PISA 2012 background questionnaire #' -#' A correlation matrix for the selected background questionnaires and +#' A correlation matrix for the selected background questionnaires and #' mathematics plausible value. #' #' @format An 19 by 19 matrix. -#' +#' #' @section Details: -#' -#' A heterogenous correlation matrix, consisting of polyserial correlations -#' between numeric and ordinal variables, and polychoric correlations between +#' +#' A heterogeneous correlation matrix, consisting of polyserial correlations +#' between numeric and ordinal variables, and polychoric correlations between #' ordinal variables. -#' +#' #' \tabular{llll}{ #' \strong{Row/Col} \tab \strong{Name} \tab \strong{Label} \tab \strong{Type} \cr -#' 1 \tab ST93Q01 \tab Perseverance \tab Ordinal \cr -#' 2 \tab ST93Q03 \tab Perseverance \tab Ordinal \cr -#' 3 \tab ST93Q04 \tab Perseverance \tab Ordinal \cr -#' 4 \tab ST93Q06 \tab Perseverance \tab Ordinal \cr -#' 5 \tab ST93Q07 \tab Perseverance \tab Ordinal \cr +#' 1 \tab ST93Q01 \tab Perseverance \tab Ordinal \cr +#' 2 \tab ST93Q03 \tab Perseverance \tab Ordinal \cr +#' 3 \tab ST93Q04 \tab Perseverance \tab Ordinal \cr +#' 4 \tab ST93Q06 \tab Perseverance \tab Ordinal \cr +#' 5 \tab ST93Q07 \tab Perseverance \tab Ordinal \cr #' 6 \tab ST94Q05 \tab Openness for Problem Solving \tab Ordinal \cr #' 7 \tab ST94Q06 \tab Openness for Problem Solving \tab Ordinal \cr #' 8 \tab ST94Q09 \tab Openness for Problem Solving \tab Ordinal \cr #' 9 \tab ST94Q10 \tab Openness for Problem Solving \tab Ordinal \cr -#' 10 \tab ST94Q14 \tab Openness for Problem Solving \tab Ordinal \cr -#' 11 \tab ST88Q01 \tab Attitude toward School \tab Ordinal \cr -#' 12 \tab ST88Q02 \tab Attitude toward School \tab Ordinal \cr -#' 13 \tab ST88Q03 \tab Attitude toward School \tab Ordinal \cr -#' 14 \tab ST88Q04 \tab Attitude toward School \tab Ordinal \cr -#' 15 \tab ST89Q02 \tab Attitude toward School \tab Ordinal \cr -#' 16 \tab ST89Q03 \tab Attitude toward School \tab Ordinal \cr -#' 17 \tab ST89Q04 \tab Attitude toward School \tab Ordinal \cr -#' 18 \tab ST89Q05 \tab Attitude toward School \tab Ordinal \cr +#' 10 \tab ST94Q14 \tab Openness for Problem Solving \tab Ordinal \cr +#' 11 \tab ST88Q01 \tab Attitude toward School \tab Ordinal \cr +#' 12 \tab ST88Q02 \tab Attitude toward School \tab Ordinal \cr +#' 13 \tab ST88Q03 \tab Attitude toward School \tab Ordinal \cr +#' 14 \tab ST88Q04 \tab Attitude toward School \tab Ordinal \cr +#' 15 \tab ST89Q02 \tab Attitude toward School \tab Ordinal \cr +#' 16 \tab ST89Q03 \tab Attitude toward School \tab Ordinal \cr +#' 17 \tab ST89Q04 \tab Attitude toward School \tab Ordinal \cr +#' 18 \tab ST89Q05 \tab Attitude toward School \tab Ordinal \cr #' 19 \tab 1PV1MATH \tab Mathematics Plausible Value 1 \tab Continuous \cr #' } -#' +#' #' @section Warning: -#' -#' These data are for illustration purposes only. Handling of missing data may not be suitable for valid inferences. -#' -#' @source +#' +#' These data are for illustration purposes only. Handling of missing data may not be suitable for valid inferences. +#' +#' @source #' Raw data can be found at \url{https://www.oecd.org/pisa/pisaproducts/pisa2012database-downloadabledata.htm} #' Codebook can be found at \url{https://www.oecd.org/pisa/pisaproducts/PISA12_stu_codebook.pdf} -#' -"pisa2012_q_cormat" \ No newline at end of file +#' +"pisa2012_q_cormat" diff --git a/R/summary.R b/R/summary.R index 41aa3cb..3444873 100644 --- a/R/summary.R +++ b/R/summary.R @@ -2,7 +2,7 @@ #' @description Takes the output of `cluster_gen` and creates summary statistics of the questionnaire variables #' @param object output of `cluster_gen` #' @param digits loosely controls the number of digits (significant or not) in the output (for `print = TRUE`) -#' @param print "all" will pretty-print a summary of statistics, "partial" will only print cluster-level sumamrizes; "none" outputs statistics as a list +#' @param print "all" will pretty-print a summary of statistics, "partial" will only print cluster-level summaries; "none" outputs statistics as a list #' @param print_hetcor if `TRUE` (default), prints the heterogeneous correlation matrix #' @param force_matrix if `TRUE`, prints the heterogeneous correlation matrix even if warnings are generated #' @param ... additional arguments (unused; added for compatibility with generic) diff --git a/R/trim_sample.R b/R/trim_sample.R index 9e749b0..49431c9 100644 --- a/R/trim_sample.R +++ b/R/trim_sample.R @@ -1,7 +1,7 @@ #' @title Trim sample #' @description Makes sure n <= N -#' @param n vector or unranged list corresponding to sample structure -#' @param N vector or unranged list corresponding to population structure +#' @param n vector or non-ranged list corresponding to sample structure +#' @param N vector or non-ranged list corresponding to population structure #' @seealso cluster_gen #' @export trim_sample <- function(n, N) { @@ -19,4 +19,4 @@ trim_sample <- function(n, N) { n_lab <- label_respondents(n, add_last_level = TRUE, apply_labels = FALSE) N_lab <- label_respondents(N, add_last_level = TRUE, apply_labels = FALSE) return(n) -} \ No newline at end of file +} diff --git a/R/validate.R b/R/validate.R index fb9c9d8..ae1e0d2 100644 --- a/R/validate.R +++ b/R/validate.R @@ -1,5 +1,5 @@ #' Wrapper-functions for check_condition -#' @description functions to save space in ther parent functions by moving the validation checks here +#' @description functions to save space in their parent functions by moving the validation checks here #' @param n_cats vector with number of categories for each categorical variable #' (W) #' @param n_vars number of variables (Y, X and W) diff --git a/R/weight_responses.R b/R/weight_responses.R index f8016b1..47a5856 100644 --- a/R/weight_responses.R +++ b/R/weight_responses.R @@ -4,8 +4,8 @@ #' @param n_obs list with the number of elements per level #' @param N list of numeric vector with the population size of each *sampled* cluster element on each level #' @param lvl number of the current level -#' @param sublvl number of the current sublevel (element within level) -#' @param previous_sublvl number of the sublevel of the parent level +#' @param sublvl number of the current sub-level (element within level) +#' @param previous_sublvl number of the sub-level of the parent level #' @param sampling_method can be "SRS" for Simple Random Sampling or "PPS" for Probabilities Proportional to Size #' @param cluster_labels character vector with the names of each cluster level #' @param resp_labels character vector with the names of the questionnaire respondents on each level @@ -113,4 +113,4 @@ weight_responses <- function(cluster_bg, n_obs, N, lvl, sublvl, previous_sublvl, cluster_bg[label_ij] <- w_ij return(cluster_bg) -} \ No newline at end of file +} diff --git a/README.md b/README.md index 0af9ce9..656d495 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Current CRAN release](https://www.r-pkg.org/badges/version/lsasim) [![Build Status](https://travis-ci.org/tmatta/lsasim.svg?branch=master)](https://travis-ci.org/tmatta/lsasim) +![Current CRAN release](https://www.r-pkg.org/badges/version/lsasim) [![R-CMD-check](https://github.com/tmatta/lsasim/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmatta/lsasim/actions/workflows/R-CMD-check.yaml) # LSASIM diff --git a/cran-comments.md b/cran-comments.md index 5153590..b602e87 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,8 +1,27 @@ +Dear CRAN Team, +this is a resubmission of package 'lsasim'. I have added the following changes: + +## Bug fixes + +* Fixed `block_design()` for non-sequential items (issue #50) +* Fixed typos in documentation +* Reimplemented continuous integration routine (issue #47) + +Please upload to CRAN. +Best, Waldir + +# Package lsasim 2.1.5 + +Reporting is done by packager version 1.15.2 + + ## Test environments -* local GNU/Linux installs (Arch and Ubuntu 18.04), R 3.6.1 -* win-builder (devel and release) -* ubuntu 12.04 (on travis-ci), R 3.3.2 +- R version 4.3.3 (2024-02-29) + Platform: x86_64-pc-linux-gnu (64-bit) + Running under: EndeavourOS + ERROR: No check log found! +- win-builder (devel) -## R CMD check results -There were no ERRORs, WARNINGS, or NOTEs. +## Local test results +## Local meta results diff --git a/man/anova.lsasimcluster.Rd b/man/anova.lsasimcluster.Rd index 6d5b2d1..49fdb0d 100644 --- a/man/anova.lsasimcluster.Rd +++ b/man/anova.lsasimcluster.Rd @@ -11,7 +11,7 @@ \item{print}{if `TRUE`, output will be a list containing estimators; if `FALSE` (default), output are formatted tables of this information} -\item{calc.se}{if `TRUE`, will try to calculate the standard error of the intreaclass correlation} +\item{calc.se}{if `TRUE`, will try to calculate the standard error of the intraclass correlation} \item{...}{additional objects of the same type (see `help("anova")` for details)} } diff --git a/man/beta_gen.Rd b/man/beta_gen.Rd index 4ff681e..9bd7653 100644 --- a/man/beta_gen.Rd +++ b/man/beta_gen.Rd @@ -51,7 +51,7 @@ Uses the output from questionnaire_gen to generate linear regression coefficients. } \details{ -This function was primarily conceived as a subfunction of +This function was primarily conceived as a sub-function of \code{questionnaire_gen}, when \code{family = "gaussian"}, \code{theta = TRUE}, and \code{full_output = TRUE}. However, it can also be directly called by the user so they can perform further analysis. diff --git a/man/block_design.Rd b/man/block_design.Rd index 55223a8..990c5c5 100644 --- a/man/block_design.Rd +++ b/man/block_design.Rd @@ -14,15 +14,15 @@ block_design(n_blocks = NULL, item_parameters, item_block_matrix = NULL) \item{item_block_matrix}{a matrix of indicators to assign items to blocks.} } \description{ -\code{block_design} creates a length-2 list containing: +\code{block_design} creates a length-2 list containing: \itemize{ \item a matrix that identifies which items correspond to which blocks and - \item a table of block descriptive statisics. + \item a table of block descriptive statistics. } } \section{Warning}{ -The default \code{item_block_matrix} spirals the items across the \code{n_blocks} and requires \code{n_blocks} >= 3. +The default \code{item_block_matrix} spirals the items across the \code{n_blocks} and requires \code{n_blocks} >= 3. If \code{n_blocks} < 3, \code{item_block_matrix} must be specified. The columns of \code{item_block_matrix} represent each block while the rows @@ -33,7 +33,7 @@ block 2 does not contain item 1. \examples{ item_param <- data.frame(item = seq(1:25), b = runif(25, -2, 2)) -ib_matrix <- matrix(nrow = 25, ncol = 5, byrow = FALSE, +ib_matrix <- matrix(nrow = 25, ncol = 5, byrow = FALSE, c(1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, diff --git a/man/booklet_design.Rd b/man/booklet_design.Rd index 19716bf..b9b9a6c 100644 --- a/man/booklet_design.Rd +++ b/man/booklet_design.Rd @@ -20,23 +20,23 @@ If using \code{booklet_design} in tandem with \code{block_design}, \code{item_bl is the the first element of the returned list of \code{block_design}. The columns of \code{item_block_assignment} represent each block while the rows -represent the number of items in each block. Becuase the number of items per -block can vary, the number of rows represents the block with the most items. The -contets of \code{item_block_assignment} is the actual item numbers. The remainer of -shorter blocks are filled with zeros. +represent the number of items in each block. Because the number of items per +block can vary, the number of rows represents the block with the most items. The +contents of \code{item_block_assignment} is the actual item numbers. The remainder of +shorter blocks are filled with zeros. The columns of \code{book_design} represent each book while the rows represent each block. The default \code{book_design} assigns two blocks to every booklet in a spiral design. -The number of default booklets is equal to the number of blocks and must be >= 3. +The number of default booklets is equal to the number of blocks and must be >= 3. If \code{ncol(item_block_assignment)} < 3, \code{book_design} must be specified. } \examples{ -i_blk_mat <- matrix(seq(1:40), ncol = 5) +i_blk_mat <- matrix(seq(1:40), ncol = 5) blk_book <- matrix(c(1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, - 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0), + 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0), ncol = 5, byrow = TRUE) booklet_design(item_block_assignment = i_blk_mat, book_design = blk_book) booklet_design(item_block_assignment = i_blk_mat) diff --git a/man/brr.Rd b/man/brr.Rd index 3f1ddaa..4b322f1 100644 --- a/man/brr.Rd +++ b/man/brr.Rd @@ -43,7 +43,7 @@ PISA uses the BRR Fay method with \eqn{k = 0.5}. } \references{ OECD (2015). Pisa Data Analysis Manual. -Adams, R., & Wu, M. (2002). PISA 2000 Technical Report. Paris: Organisation for Economic Co-operation and Development (OECD). +Adams, R., & Wu, M. (2002). PISA 2000 Technical Report. Paris: Organization for Economic Co-operation and Development (OECD). Rust, K. F., & Rao, J. N. K. (1996). Variance estimation for complex surveys using replication techniques. Statistical methods in medical research, 5(3), 283-310. } \seealso{ diff --git a/man/calc_replicate_weights.Rd b/man/calc_replicate_weights.Rd index 7800eb0..899b567 100644 --- a/man/calc_replicate_weights.Rd +++ b/man/calc_replicate_weights.Rd @@ -14,7 +14,7 @@ calc_replicate_weights(data, method, k = 0) \item{k}{deflating weight factor (used only when `method = "BRR Fay")} } \value{ -list with data and, if requeted, some statistics +list with data and, if requested, some statistics } \description{ Takes the output of `cluster_gen` to calculate the replicate weights as well as some summary statistics diff --git a/man/cluster_gen.Rd b/man/cluster_gen.Rd index fb3c358..5611342 100644 --- a/man/cluster_gen.Rd +++ b/man/cluster_gen.Rd @@ -78,7 +78,7 @@ list with background questionnaire data, grouped by level or not Generate cluster sample } \details{ -This function relies heavily in two subfunctions---`cluster_gen_separate` and `cluster_gen_together`---which can be called independently. This does not make `cluster_gen` a simple wrapper function, as it performs several operations prior to calling its subfunctions, such as randomly generating `n_X` and `n_W` if they are not determined by user. +This function relies heavily in two sub-functions---`cluster_gen_separate` and `cluster_gen_together`---which can be called independently. This does not make `cluster_gen` a simple wrapper function, as it performs several operations prior to calling its sub-functions, such as randomly generating `n_X` and `n_W` if they are not determined by user. `n` can have unitary length, in which case all clusters will have the same size. `N` is *not* the population size across all elements of a level, but the population size for each element of one level. Regarding the additional parameters to be passed to `questionnaire_gen()`, they can be passed either in the same format as `questionnaire_gen()` or as more complex objects that contain information for each cluster level. @@ -86,7 +86,7 @@ Regarding the additional parameters to be passed to `questionnaire_gen()`, they \note{ For the purpose of this function, levels are counted starting from the top nesting/clustering level. This means that, for example, schools are the first cluster level, classes are the second, and students are the third and final level. This behavior can be customized by naming the `n` argument or providing custom labels in `cluster_labels` and `resp_labels`. -Manually setting both `c_mean` and `rho`, while possible, may yield unexpected results due to how those parameters work together. A high intraclass correlation (`rho`) teoretically means that each group will end up with different means so they can be better separated. If `c_mean` is left untouched (i.e., at the default value of zero), then `c_mean` will freely change between clusters in order to result in the expected intraclass correlation. For large samples, `c_mean` will in practice correspond to the grand mean across that level, as the means of each element will be different no matter the sample size. +Manually setting both `c_mean` and `rho`, while possible, may yield unexpected results due to how those parameters work together. A high intraclass correlation (`rho`) theoretically means that each group will end up with different means so they can be better separated. If `c_mean` is left untouched (i.e., at the default value of zero), then `c_mean` will freely change between clusters in order to result in the expected intraclass correlation. For large samples, `c_mean` will in practice correspond to the grand mean across that level, as the means of each element will be different no matter the sample size. Moreover, if `c_mean`, `sigma` and `rho` are passed to the function, the means will be recalculated as a function of the other two parameters. The three are interdependent and cannot be passed simultaneously. diff --git a/man/cluster_gen_separate.Rd b/man/cluster_gen_separate.Rd index 5fe9d79..f7cafb5 100644 --- a/man/cluster_gen_separate.Rd +++ b/man/cluster_gen_separate.Rd @@ -72,7 +72,7 @@ corresponds to the \code{theta}.} \item{...}{Additional parameters to be passed to `questionnaire_gen()`} } \description{ -This is a subfunction of `cluster_gen` that performs cluster sampling, with the twist that each cluster level has its own questionnaire. +This is a sub-function of `cluster_gen` that performs cluster sampling, with the twist that each cluster level has its own questionnaire. } \seealso{ cluster_gen cluster_gen_together diff --git a/man/cluster_gen_together.Rd b/man/cluster_gen_together.Rd index b16ced3..48b29f7 100644 --- a/man/cluster_gen_together.Rd +++ b/man/cluster_gen_together.Rd @@ -65,7 +65,7 @@ corresponds to the \code{theta}.} \item{...}{Additional parameters to be passed to `questionnaire_gen()`} } \description{ -This is a subfunction of `cluster_gen` that performs cluster sampling where only the lowest-level individuals (e.g. students) fill out questionnaires. +This is a sub-function of `cluster_gen` that performs cluster sampling where only the lowest-level individuals (e.g. students) fill out questionnaires. } \seealso{ cluster_gen cluster_gen_separate cluster_gen_together diff --git a/man/irt_gen.Rd b/man/irt_gen.Rd index 8fc5b35..9eddbe2 100644 --- a/man/irt_gen.Rd +++ b/man/irt_gen.Rd @@ -15,7 +15,7 @@ irt_gen(theta, a_par = 1, b_par, c_par = 0, D = 1) \item{c_par}{numeric guessing parameter.} -\item{D}{numeric parameter to specify logisitic (1) or normal (1.7).} +\item{D}{numeric parameter to specify logistic (1) or normal (1.7).} } \description{ Creates a data frame of item parameters. diff --git a/man/lsasim.Rd b/man/lsasim.Rd index 3c2436e..5662645 100644 --- a/man/lsasim.Rd +++ b/man/lsasim.Rd @@ -2,8 +2,8 @@ % Please edit documentation in R/lsasim.R \docType{package} \name{lsasim} -\alias{lsasim} \alias{lsasim-package} +\alias{lsasim} \title{lsasim: A package for simulating large scale assessment data} \description{ lsasim simulates data that mimics large-scale assessments (LSAs), including background questionnaire data and cognitive item responses that adhere to a multiple-matrix sampled design diff --git a/man/pisa2012_q_cormat.Rd b/man/pisa2012_q_cormat.Rd index 2d909d7..ba8ee32 100644 --- a/man/pisa2012_q_cormat.Rd +++ b/man/pisa2012_q_cormat.Rd @@ -15,36 +15,36 @@ Codebook can be found at \url{https://www.oecd.org/pisa/pisaproducts/PISA12_stu_ pisa2012_q_cormat } \description{ -A correlation matrix for the selected background questionnaires and +A correlation matrix for the selected background questionnaires and mathematics plausible value. } \section{Details}{ -A heterogenous correlation matrix, consisting of polyserial correlations -between numeric and ordinal variables, and polychoric correlations between +A heterogeneous correlation matrix, consisting of polyserial correlations +between numeric and ordinal variables, and polychoric correlations between ordinal variables. \tabular{llll}{ \strong{Row/Col} \tab \strong{Name} \tab \strong{Label} \tab \strong{Type} \cr - 1 \tab ST93Q01 \tab Perseverance \tab Ordinal \cr - 2 \tab ST93Q03 \tab Perseverance \tab Ordinal \cr - 3 \tab ST93Q04 \tab Perseverance \tab Ordinal \cr - 4 \tab ST93Q06 \tab Perseverance \tab Ordinal \cr - 5 \tab ST93Q07 \tab Perseverance \tab Ordinal \cr + 1 \tab ST93Q01 \tab Perseverance \tab Ordinal \cr + 2 \tab ST93Q03 \tab Perseverance \tab Ordinal \cr + 3 \tab ST93Q04 \tab Perseverance \tab Ordinal \cr + 4 \tab ST93Q06 \tab Perseverance \tab Ordinal \cr + 5 \tab ST93Q07 \tab Perseverance \tab Ordinal \cr 6 \tab ST94Q05 \tab Openness for Problem Solving \tab Ordinal \cr 7 \tab ST94Q06 \tab Openness for Problem Solving \tab Ordinal \cr 8 \tab ST94Q09 \tab Openness for Problem Solving \tab Ordinal \cr 9 \tab ST94Q10 \tab Openness for Problem Solving \tab Ordinal \cr - 10 \tab ST94Q14 \tab Openness for Problem Solving \tab Ordinal \cr - 11 \tab ST88Q01 \tab Attitude toward School \tab Ordinal \cr - 12 \tab ST88Q02 \tab Attitude toward School \tab Ordinal \cr - 13 \tab ST88Q03 \tab Attitude toward School \tab Ordinal \cr - 14 \tab ST88Q04 \tab Attitude toward School \tab Ordinal \cr - 15 \tab ST89Q02 \tab Attitude toward School \tab Ordinal \cr - 16 \tab ST89Q03 \tab Attitude toward School \tab Ordinal \cr - 17 \tab ST89Q04 \tab Attitude toward School \tab Ordinal \cr - 18 \tab ST89Q05 \tab Attitude toward School \tab Ordinal \cr + 10 \tab ST94Q14 \tab Openness for Problem Solving \tab Ordinal \cr + 11 \tab ST88Q01 \tab Attitude toward School \tab Ordinal \cr + 12 \tab ST88Q02 \tab Attitude toward School \tab Ordinal \cr + 13 \tab ST88Q03 \tab Attitude toward School \tab Ordinal \cr + 14 \tab ST88Q04 \tab Attitude toward School \tab Ordinal \cr + 15 \tab ST89Q02 \tab Attitude toward School \tab Ordinal \cr + 16 \tab ST89Q03 \tab Attitude toward School \tab Ordinal \cr + 17 \tab ST89Q04 \tab Attitude toward School \tab Ordinal \cr + 18 \tab ST89Q05 \tab Attitude toward School \tab Ordinal \cr 19 \tab 1PV1MATH \tab Mathematics Plausible Value 1 \tab Continuous \cr } } diff --git a/man/summary.lsasimcluster.Rd b/man/summary.lsasimcluster.Rd index 9a2fc81..3fe1ac7 100644 --- a/man/summary.lsasimcluster.Rd +++ b/man/summary.lsasimcluster.Rd @@ -18,7 +18,7 @@ \item{digits}{loosely controls the number of digits (significant or not) in the output (for `print = TRUE`)} -\item{print}{"all" will pretty-print a summary of statistics, "partial" will only print cluster-level sumamrizes; "none" outputs statistics as a list} +\item{print}{"all" will pretty-print a summary of statistics, "partial" will only print cluster-level summaries; "none" outputs statistics as a list} \item{print_hetcor}{if `TRUE` (default), prints the heterogeneous correlation matrix} diff --git a/man/trim_sample.Rd b/man/trim_sample.Rd index 1c9f264..09eae48 100644 --- a/man/trim_sample.Rd +++ b/man/trim_sample.Rd @@ -7,9 +7,9 @@ trim_sample(n, N) } \arguments{ -\item{n}{vector or unranged list corresponding to sample structure} +\item{n}{vector or non-ranged list corresponding to sample structure} -\item{N}{vector or unranged list corresponding to population structure} +\item{N}{vector or non-ranged list corresponding to population structure} } \description{ Makes sure n <= N diff --git a/man/validate_questionnaire_gen.Rd b/man/validate_questionnaire_gen.Rd index c0b912b..ca0a58e 100644 --- a/man/validate_questionnaire_gen.Rd +++ b/man/validate_questionnaire_gen.Rd @@ -41,5 +41,5 @@ background variables} \item{c_sd}{vector of standard deviations of all variables (YXW)} } \description{ -functions to save space in ther parent functions by moving the validation checks here +functions to save space in their parent functions by moving the validation checks here } diff --git a/man/weight_responses.Rd b/man/weight_responses.Rd index fbe3ca6..49d87b5 100644 --- a/man/weight_responses.Rd +++ b/man/weight_responses.Rd @@ -27,9 +27,9 @@ weight_responses( \item{lvl}{number of the current level} -\item{sublvl}{number of the current sublevel (element within level)} +\item{sublvl}{number of the current sub-level (element within level)} -\item{previous_sublvl}{number of the sublevel of the parent level} +\item{previous_sublvl}{number of the sub-level of the parent level} \item{sampling_method}{can be "SRS" for Simple Random Sampling or "PPS" for Probabilities Proportional to Size} diff --git a/tests/testthat/test.issue50.R b/tests/testthat/test.issue50.R new file mode 100644 index 0000000..6d9d5ee --- /dev/null +++ b/tests/testthat/test.issue50.R @@ -0,0 +1,26 @@ +# Adapted from https://github.com/tmatta/lsasim/issues/50#issue-2254039296 + +# Data and subset +set.seed(8078908) +param <- NAEPirtparams::parameters +item_par <- param[param$level %in% 8 & param$subject %in% "Mathematics" & param$year %in% 2015, ] + +# Happy path +item_par_1 <- item_par +item_par_1$item <- sample(1e5, nrow(item_par_1)) +block_1 <- block_design(10L, item_par_1) + +# Sequential items +item_par_2 <- item_par +item_par_2$item <- seq(1, nrow(item_par_2)) +block_2 <- block_design(10L, item_par_2) + +# Tests +test_that("Results are independent of item numbering", { + expect_identical(block_1$block_descriptives, block_2$block_descriptives) +}) +test_that("Errors are properly triggered", { + expect_error(block_design(10L, item_par), "must contain an 'item' column.") + item_par$item <- sample(100, size = nrow(item_par), replace = TRUE) + expect_error(block_design(10L, item_par), "must contain unique 'item'.") +}) diff --git a/vignettes/ex1_BackgroundQuestionnaireGeneration.Rmd b/vignettes/ex1_BackgroundQuestionnaireGeneration.Rmd index 7b32815..0298a74 100644 --- a/vignettes/ex1_BackgroundQuestionnaireGeneration.Rmd +++ b/vignettes/ex1_BackgroundQuestionnaireGeneration.Rmd @@ -42,7 +42,7 @@ The function `questionnaire_gen` generates correlated continuous and ordinal dat * `n_vars`: the number of variables, including the continuous (`X`) and the ordinal (`W`) covariates as well as the latent trait (`theta`). * `n_X`: the number of continuous (`X`) variables. * `n_W`: the number of ordinal (`W`) variables. -* `cor_matrix`: a possibly heterogenous correlation matrix, consisting of polyserial correlations between continuous and ordinal variables, and polychoric correlations between ordinal variables. +* `cor_matrix`: a possibly heterogeneous correlation matrix, consisting of polyserial correlations between continuous and ordinal variables, and polychoric correlations between ordinal variables. * `cov_matrix`: a covariance matrix, formatted as `cov_matrix`. The arguments `c_mean` and `c_sd` are scaling parameters for continuous variables. If the logical argument `theta` is `TRUE` then the latent trait will be generated as the first continuous variable and labeled 'theta'. If `family` is `gaussian` then the data will be generated from a multivariate normal distribution, or the data will be generated from the polychoric correlation matrix. @@ -81,7 +81,7 @@ str(bg) --- -In addition to `n_vars = 4`, we specify the logical argument `theta = TRUE`. Three different item types are generated, two 1-category item (latent trait and continuous), one 2-category item, and one 5-category item. It is noted that when `theta = TRUE`, the first continuous variable generated is alwasy labeled `theta`. +In addition to `n_vars = 4`, we specify the logical argument `theta = TRUE`. Three different item types are generated, two 1-category item (latent trait and continuous), one 2-category item, and one 5-category item. It is noted that when `theta = TRUE`, the first continuous variable generated is always labeled `theta`. ```{r ex 2b} set.seed(4388) @@ -160,4 +160,4 @@ bg <- questionnaire_gen(n_obs = 100, cat_prop = props, cov_matrix = yw_cov, c_mean = 2, family = "gaussian") str(bg) -``` \ No newline at end of file +``` diff --git a/vignettes/ex4_GeneratingClusterSamples.Rmd b/vignettes/ex4_GeneratingClusterSamples.Rmd index be91478..42a6d9d 100644 --- a/vignettes/ex4_GeneratingClusterSamples.Rmd +++ b/vignettes/ex4_GeneratingClusterSamples.Rmd @@ -68,7 +68,7 @@ The function `cluster_gen` generates clustered samples which resembles the compo * `rho`: specifies the estimated intraclass correlation. * `verbose`: if the logical argument `verbose` is 'TRUE', then messages are printed in the output. * `print_pop_structure`: if `print_pop_structure` is 'TRUE', then the population hierarchical structure is printed out (as long as it differs from the sample structure). -* `...`: additional parameterss to be passed to `questionnaire_gen()`. +* `...`: additional parameters to be passed to `questionnaire_gen()`. ---