|
904 | 904 | result <- list(model = model, data = data, pars = pars) |
905 | 905 | return(result) |
906 | 906 | } |
| 907 | + |
| 908 | +.irtDifAnalysisTable <- function(dataset, options, jaspResults, ready, position) { |
| 909 | + if (options[["explanatoryText"]] && options[["tableDifAnalysis"]]) { |
| 910 | + text <- createJaspHtml(gettext("<h3>Explanatory Text: Differential Item Functioning (DIF)</h3> The table below presents the results of a Differential Item Functioning (DIF) analysis. A DIF-analysis is conducted to assess whether specific items perform differently across groups while controlling for overall ability or trait levels. This ensures that the items are fair and not biased toward any particular group.")) |
| 911 | + text$position <- position |
| 912 | + text$dependOn(options = c("explanatoryText", "tableDifAnalysis")) |
| 913 | + jaspResults[["tableDifAnalysisText"]] <- text |
| 914 | + } |
| 915 | + if (!is.null(jaspResults[["tableDifAnalysis"]]) || !options[["tableDifAnalysis"]]) { |
| 916 | + return() |
| 917 | + } |
| 918 | + tb <- createJaspTable(title = gettext("Differential Item Functioning (DIF)")) |
| 919 | + tb$position <- position + 1 |
| 920 | + tb$addColumnInfo(name = "item", title = gettext("Item"), type = "string") |
| 921 | + tb$addColumnInfo(name = "aic", title = gettext("AIC"), type = "number") |
| 922 | + tb$addColumnInfo(name = "sabic", title = gettext("SABIC"), type = "number") |
| 923 | + tb$addColumnInfo(name = "hq", title = gettext("HQ"), type = "number") |
| 924 | + tb$addColumnInfo(name = "bic", title = gettext("BIC"), type = "number") |
| 925 | + tb$addColumnInfo(name = "x2", title = gettext("X2"), type = "number") |
| 926 | + tb$addColumnInfo(name = "df", title = gettext("df"), type = "number") |
| 927 | + tb$addColumnInfo(name = "p", title = gettext("p"), type = "pvalue") |
| 928 | + tb$dependOn(options = c(.irtCommonDeps(type = "irt"), "tableDifAnalysis", "groupingVariable", "tableDifAnalysisDifficulty", "tableDifAnalysisDiscrimination", "tableDifAnalysisGuess", "tableDifAnalysisSlip")) |
| 929 | + tb$addFootnote(gettext("For each item, the null hypothesis specifies that there is no DIF between the groups.")) |
| 930 | + tb$addFootnote(gettext("p-values are not adjusted for multiple comparisons."), colName = "p") |
| 931 | + if (length(options[["covariates"]]) > 0) { |
| 932 | + tb$addFootnote(gettext("The latent regressions present in the ungrouped model are not included in this analysis.")) |
| 933 | + } |
| 934 | + jaspResults[["tableDifAnalysis"]] <- tb |
| 935 | + if (!ready || options[["groupingVariable"]] == "") { |
| 936 | + return() |
| 937 | + } |
| 938 | + parameters <- character() |
| 939 | + if (options[["tableDifAnalysisDifficulty"]]) { |
| 940 | + parameters <- c(parameters, "d") |
| 941 | + } |
| 942 | + if (options[["tableDifAnalysisDiscrimination"]] && options[["model"]] %in% c("2PL", "3PL", "4PL")) { |
| 943 | + parameters <- c(parameters, "a1") |
| 944 | + } |
| 945 | + if (options[["tableDifAnalysisGuess"]] && options[["model"]] %in% c("3PL", "4PL")) { |
| 946 | + parameters <- c(parameters, "d") |
| 947 | + } |
| 948 | + if (options[["tableDifAnalysisSlip"]] && options[["model"]] == "4PL") { |
| 949 | + parameters <- c(parameters, "u") |
| 950 | + } |
| 951 | + if (length(parameters) == 0) { |
| 952 | + tb$setError(gettext("DIf-analysis not possible: Select at least one parameter to test.")) |
| 953 | + return() |
| 954 | + } |
| 955 | + state <- .irtIRTStateBayesian(dataset, options, jaspResults) |
| 956 | + fit <- mirt::multipleGroup(data = state[["items"]], model = 1, itemtype = options[["model"]], group = dataset[[options[["groupingVariable"]]]], SE = FALSE, verbose = FALSE, TOL = options[["emTolerance"]], technical = list(NCYCLES = options[["emIterations"]], set.seed = options[["seed"]])) |
| 957 | + dif <- mirt::DIF(fit, which.par = parameters) |
| 958 | + tb[["item"]] <- options[["items"]] |
| 959 | + tb[["aic"]] <- dif[["AIC"]] |
| 960 | + tb[["sabic"]] <- dif[["SABIC"]] |
| 961 | + tb[["hq"]] <- dif[["HQ"]] |
| 962 | + tb[["bic"]] <- dif[["BIC"]] |
| 963 | + tb[["x2"]] <- dif[["X2"]] |
| 964 | + tb[["df"]] <- dif[["df"]] |
| 965 | + tb[["p"]] <- dif[["p"]] |
| 966 | +} |
0 commit comments