Skip to content

Commit c0c3c10

Browse files
committed
add K to itemstats
1 parent 1692d85 commit c0c3c10

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

R/itemstats.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#' Generic item summary statistics
22
#'
33
#' Function to compute generic item summary statistics that do not require
4-
#' prior fitting of IRT models. Contains information about coefficient alpha
4+
#' prior fitting of IRT models. Contains information about sample sizes (\code{N}),
5+
#' number of observed categories (\code{K}), coefficient alpha
56
#' (and alpha if an item is deleted), mean/SD and frequency of total scores,
67
#' reduced item-total correlations, average/sd of the correlation between items,
78
#' response frequencies, and conditional mean/sd information given the
@@ -117,6 +118,7 @@ itemstats <- function(data, group = NULL,
117118
overall$SEM.alpha <- with(overall, sd_total.score * sqrt(1-alpha))
118119
rownames(overall) <- ""
119120
df <- data.frame(N=apply(data, 2, function(x) sum(!is.na(x))),
121+
K=apply(data, 2, \(x) length(unique(na.omit(x)))),
120122
mean=colMeans(data, na.rm = TRUE),
121123
sd=apply(data, 2, sd, na.rm = TRUE),
122124
total.r=itemcor,
@@ -125,6 +127,7 @@ itemstats <- function(data, group = NULL,
125127
} else {
126128
overall <- data.frame(N.complete=sum(!is.na(TS_miss)), N=nrow(data))
127129
df <- data.frame(N=apply(data, 2, function(x) sum(!is.na(x))),
130+
K=apply(data, 2, \(x) length(unique(na.omit(x)))),
128131
mean=colMeans(data, na.rm = TRUE),
129132
sd=apply(data, 2, sd, na.rm = TRUE))
130133
}

man/itemstats.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)