Skip to content

Commit 1f228d9

Browse files
committed
fix sem things for the tutorial
1 parent 7d15e82 commit 1f228d9

File tree

8 files changed

+343
-218
lines changed

8 files changed

+343
-218
lines changed

R/standardErrorOfMeasurement.R

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ standardErrorOfMeasurement <- function(jaspResults, dataset, options) {
7777
exitAnalysisIfErrors = TRUE)
7878

7979
if (options[["lord2"]] && options[["lord2NumberOfSplits"]] == "") {
80-
.quitAnalysis(gettext("For the Lord's compound method, the test could not be split in equally sized parts with more than 1 item per part. Consider adding or removing items."))
80+
.quitAnalysis(gettext("For the Lord generalized method, the test could not be split in equally sized parts with more than 1 item per part. Consider adding or removing items."))
8181
}
8282
}
8383

@@ -128,7 +128,7 @@ standardErrorOfMeasurement <- function(jaspResults, dataset, options) {
128128
# at least one method is selected
129129
for (i in 1:length(selected)) {
130130
if (is.na(selected[[i]][["name"]])) {
131-
.quitAnalysis(gettext("The Lord, Keats, and Lord's compound method are only available for binary data."))
131+
.quitAnalysis(gettext("The Lord, Keats, and Lord generalized method are only available for binary data."))
132132
}
133133
if (is.null(jaspResults[["semMainContainer"]][[paste0(method[i], "State")]])) {
134134
out <- eval(parse(text = selected[[i]][["funString"]]))
@@ -485,15 +485,15 @@ standardErrorOfMeasurement <- function(jaspResults, dataset, options) {
485485
pl <- ggplot2::ggplot(dat) +
486486
ggplot2::geom_point(ggplot2::aes(x = score, y = tscore), size = 2.5) +
487487
ggplot2::geom_errorbar(ggplot2::aes(x = score, ymin = lower, ymax = upper), width = 0.5) +
488-
ggplot2::labs(x = gettext("Sum Score"), y = gettext("True Score"))
488+
ggplot2::labs(x = gettext("Sum Score"), y = gettext("True Score Estimate"))
489489
} else {
490490
dat <- as.data.frame(ciData)
491491
colnames(dat) <- c("score", "lower", "upper")
492492
dat$tscore <- dat$score
493493
pl <- ggplot2::ggplot(dat) +
494494
ggplot2::geom_ribbon(ggplot2::aes(x = score, ymin = lower, ymax = upper), fill = "grey80") +
495495
ggplot2::geom_line(ggplot2::aes(x = score, y = tscore)) +
496-
ggplot2::labs(x = gettext("Sum Score"), y = gettext("True Score"))
496+
ggplot2::labs(x = gettext("Sum Score"), y = gettext("True Score Estimate"))
497497
}
498498

499499
if (!is.na(cutoff)) {
@@ -539,8 +539,19 @@ standardErrorOfMeasurement <- function(jaspResults, dataset, options) {
539539
out <- .semPrepareOutMatrix(ncol(X), nc, scoresObj)
540540
fun <- function(partSUMS, ind, cc) {
541541
K <- ncol(partSUMS)
542-
mean_diff <- partSUMS[ind, ] - rowMeans(partSUMS[ind, ]) - matrix(colMeans(partSUMS[ind, ]), length(ind), K, TRUE) + mean(partSUMS[ind, ])
543-
ret <- sqrt(d * sum(rowSums(mean_diff^2) / (K - 1)) / length(ind))
542+
# mean_diff <- partSUMS[ind, ] - rowMeans(partSUMS[ind, ]) - matrix(colMeans(partSUMS[ind, ]), length(ind), K, TRUE) + mean(partSUMS[ind, ])
543+
# ret <- sqrt(d * sum(rowSums(mean_diff^2) / (K - 1)) / length(ind))
544+
545+
col_means <- colMeans(partSUMS) # Global marginal means (X_j)
546+
grand_mean <- mean(col_means) # Global grand mean (M)
547+
row_means <- rowMeans(partSUMS[ind, ]) # Person means (X_i)
548+
549+
# Construct Feldt's deviation term
550+
mean_diff <- partSUMS[ind, ] -
551+
matrix(row_means, length(ind), K, byrow = FALSE) -
552+
matrix(col_means - grand_mean, length(ind), K, byrow = TRUE)
553+
554+
ret <- sqrt( d * sum(mean_diff^2) / ((K - 1) * length(ind)) )
544555
return(ret)
545556
}
546557
out <- .semComputeWithCaseMin(out, S, caseMin, partSUMS, fun)
@@ -557,9 +568,7 @@ standardErrorOfMeasurement <- function(jaspResults, dataset, options) {
557568
out <- .semPrepareOutMatrix(ncol(X), nc, scoresObj)
558569
scores <- out[, 1]
559570

560-
rawDiffK <- d *
561-
rowSums((partSUMS - matrix(colMeans(partSUMS), N, K, TRUE) - rowMeans(partSUMS) + mean(partSUMS))^2) /
562-
(K - 1)
571+
rawDiffK <- d * rowSums((partSUMS - matrix(colMeans(partSUMS), N, K, TRUE) - rowMeans(partSUMS) + mean(partSUMS))^2) / (K - 1)
563572
betaK <- coef(lm(rawDiffK ~ poly(S, n_poly, raw = TRUE)))
564573
scrs <- sqrt(betaK[1] + rowSums(matrix(betaK[-1], length(scores), n_poly, TRUE) * poly(scores, n_poly, raw = TRUE)))
565574
out[, 2] <- scrs
@@ -882,7 +891,7 @@ standardErrorOfMeasurement <- function(jaspResults, dataset, options) {
882891
funString = NA,
883892
dependencies = NA)),
884893
lord2 = switch(as.character(nc),
885-
"2" = list(name = "Lord's compound",
894+
"2" = list(name = "Lord generalized",
886895
funString = ".semLord2(dataset, as.numeric(options$lord2NumberOfSplits), scrs, options$minimumGroupSize)",
887896
dependencies = c("lord2", "lord2NumberOfSplits", "minimumGroupSize")),
888897
list(name = NA,

inst/help/standardErrorOfMeasurement.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The Standard Error of Measurement (sem) quantifies the precision of a measuremen
2323
- Binomial methods: Based on the idea that the item scores follow a binomial distribution
2424
- Lord: Method that only requires number of correct and incorrect items
2525
- Keats: Corrects the Lord method for supposed bias and uses a reliability coefficient in the process
26-
- Lord's compound: Essentially the Lord method for multiple test parts
26+
- Lord generalized: Essentially the Lord method for multiple test parts
2727
- Number of splits: How many splits to apply, can only be a divisor of the number of items
2828

2929
### Options

inst/qml/StandardErrorOfMeasurement.qml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Form
3737
maxLevels: 50
3838
minNumericLevels: 2
3939
id: variables
40-
onCountChanged:
40+
onCountChanged:
4141
{
4242
var newValues = []
4343
for (var i = 2; i <= variables.count; i++)
@@ -81,11 +81,11 @@ Form
8181
name: "feldt"
8282
label: qsTr("Feldt")
8383
id: feldt
84-
DropDown
84+
DropDown
8585
{
8686
name: "feldtNumberOfSplits"
8787
label: qsTr("Number of splits")
88-
values: []
88+
values: [2, 3, 4, 5, 6, 7, 8, 9, 10]
8989
id: feldtNumberOfSplits
9090
}
9191
}
@@ -94,11 +94,11 @@ Form
9494
name: "mollenkopfFeldt"
9595
label: qsTr("Mollenkopf-Feldt")
9696
id: mollenkopfFeldt
97-
DropDown
97+
DropDown
9898
{
9999
name: "mollenkopfFeldtNumberOfSplits"
100100
label: qsTr("Number of splits")
101-
values: []
101+
values: [2, 3, 4, 5, 6, 7, 8, 9, 10]
102102
id: mollenkopfFeldtNumberOfSplits
103103
}
104104
IntegerField
@@ -120,7 +120,7 @@ Form
120120
name: "anova"
121121
label: qsTr("ANOVA")
122122
}
123-
123+
124124
CheckBox
125125
{
126126
name: "irt"
@@ -148,13 +148,13 @@ Form
148148
{
149149
enabled: !variables.columnsTypes.includes("ordinal")
150150
name: "lord2"
151-
label: qsTr("Lord's compound")
151+
label: qsTr("Lord generalized")
152152
id: lord2
153-
DropDown
153+
DropDown
154154
{
155155
name: "lord2NumberOfSplits"
156156
label: qsTr("Number of splits")
157-
values: []
157+
values: [2, 3, 4, 5, 6, 7, 8, 9, 10]
158158
id: lord2NumberOfSplits
159159
}
160160
}
@@ -164,7 +164,7 @@ Form
164164
{
165165
title: qsTr("Options")
166166

167-
CheckBox
167+
CheckBox
168168
{
169169
name: "sumScoreCiTable"
170170
label: qsTr("Sum score table")
@@ -177,7 +177,7 @@ Form
177177
}
178178
}
179179

180-
CheckBox
180+
CheckBox
181181
{
182182
name: "userReliability"
183183
label: qsTr("User defined reliability")
@@ -186,7 +186,7 @@ Form
186186
DoubleField
187187
{
188188
name: "reliabilityValue"
189-
label: ""
189+
label: ""
190190
max: 1
191191
defaultValue: .5
192192
}
@@ -195,17 +195,17 @@ Form
195195
IntegerField
196196
{
197197
name: "minimumGroupSize"
198-
label: qsTr("Minimum number of observations per score group")
198+
label: qsTr("Minimum number of observations per score group")
199199
min: 1
200200
defaultValue: 20
201201
}
202202

203-
CheckBox
203+
CheckBox
204204
{
205205
name: "hideTable"
206206
label: qsTr("Hide SEM table")
207207
}
208-
208+
209209
}
210210

211211
Section
@@ -216,7 +216,7 @@ Form
216216
{
217217
name: "histogramCounts"
218218
label: qsTr("Histogram of sum score counts")
219-
}
219+
}
220220

221221
CheckBox
222222
{

0 commit comments

Comments
 (0)