R Under development (unstable) (2025-04-11 r88138 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(tidyverse) # version: tidyverse_2.0.0 ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── ✔ dplyr 1.1.4 ✔ readr 2.1.5 ✔ forcats 1.0.0 ✔ stringr 1.5.1 ✔ ggplot2 3.5.2 ✔ tibble 3.2.1 ✔ lubridate 1.9.4 ✔ tidyr 1.3.1 ✔ purrr 1.0.4 ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── ✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag() ℹ Use the conflicted package () to force all conflicts to become errors > library(dplyr) #version: dplyr_1.1.4 > library(stats) # version: stats4 > library(fastDummies) # version: fastDummies_1.7.3 > library(reshape2) #version: reshape2_1.4.4 Attaching package: 'reshape2' The following object is masked from 'package:tidyr': smiths > library(testthat) Attaching package: 'testthat' The following object is masked from 'package:dplyr': matches The following object is masked from 'package:purrr': is_null The following objects are masked from 'package:readr': edition_get, local_edition The following object is masked from 'package:tidyr': matches > > ## IRT-M estimation: > #devtools::install_github("dasiegel/IRT-M") > library(IRTM) #version 1.00 Loading required package: truncnorm Loading required package: tmvtnorm Loading required package: mvtnorm Loading required package: Matrix Attaching package: 'Matrix' The following objects are masked from 'package:tidyr': expand, pack, unpack Loading required package: stats4 Loading required package: gmm Loading required package: sandwich Loading required package: RcppProgress Loading required package: RcppDist > > test_check("IRTM") -- Column specification -------------------------------------------------------- cols() Sampling... 0% 10 20 30 40 50 60 70 80 90 100% [----|----|----|----|----|----|----|----|----|----| **************************************************| [ FAIL 0 | WARN 1 | SKIP 0 | PASS 2 ] [ FAIL 0 | WARN 1 | SKIP 0 | PASS 2 ] > > context("Testing IRTM") > > test_that("Test Case One: Normal Use", { + + synth_questions <- NULL # Initialize to avoid R CMD check notes + + load("synth_questions.rda") + ## Convert numeric ordinal responses to factors + + ebdatsub <- lapply(ebdatsynth[,], factor) ## that's a list now + + ## converts the list back into a dataframe: + Y <- dummy_cols(.data=ebdatsub, + remove_selected_columns=TRUE) + + ## remove the .data that dummy_cols adds to the column names + colnames(Y) <- gsub(".data.", '', colnames(Y)) + + ## remove the data objects: + rm(ebdatsub) + rm(ebdatsynth) + + load('mcodes.rda') + + ## Only keep M-Codes with loadings or outcomes: + MCodes$encoding <- rowSums(abs(MCodes[,4:9])) + MCodes <- MCodes[which(MCodes$encoding > 0),] + + d <- 6 #number of coded dimensions + mcolumns <- c("QMap", "D1-Culture threat", + "D2-ReligionThreat", + "D3-Economic Threat", + "D4-HealthThreat", + "O1-OutcomeSupportImmigration", "O2-OutcomeSupportEU") + + combine <- MCodes[,mcolumns] %>% ## question codes and loadings + inner_join( + Y %>% + t() %>% + as.data.frame(stringsAsFactors = FALSE) %>% + type_convert() %>% + rownames_to_column(var = "question"), + by = c("QMap" = "question" ) + ) + + M_matrix <- as.data.frame(combine[, 1:(d+1)]) + + #Reverse the earlier transposition of the observations: + Y_in <- combine[, (d+2):ncol(combine)]%>% + t() %>% + as.data.frame() + + Y_in <- as.data.frame(sapply(Y_in, as.numeric)) + + ## Take the question names and + ## convert to column names + + question <- combine[,1] %>% + as.data.frame() + colnames(Y_in) <- question[,1] + rm(combine) + rm(question) + + #Run IRT-M + d=6 + irt <- irt_m(Y_in = Y_in, d = d, M_matrix = M_matrix, nsamp = 100, nburn=100, thin=1) + + expect_type(irt, "list") + expect_equal(length(irt), 5) + }) ## closes the test_that() call 0% 10 20 30 40 50 60 70 80 90 100% [----|----|----|----|----|----|----|----|----|----| **************************************************| ── Warning: Test Case One: Normal Use ────────────────────────────────────────── `type_convert()` only converts columns of type 'character'. - `df` has no columns of type 'character' Backtrace: ▆ 1. ├─MCodes[, mcolumns] %>% ... 2. ├─dplyr::inner_join(...) 3. ├─dplyr:::inner_join.data.frame(...) 4. │ └─dplyr::auto_copy(x, y, copy = copy) 5. │ ├─dplyr::same_src(x, y) 6. │ └─dplyr:::same_src.data.frame(x, y) 7. │ └─base::is.data.frame(y) 8. ├─... %>% rownames_to_column(var = "question") 9. ├─tibble::rownames_to_column(., var = "question") 10. └─readr::type_convert(.) > > proc.time() user system elapsed 66.23 1.32 67.57