Skip to content

Commit 1ae14b8

Browse files
committed
option for raw counts
1 parent deb29f5 commit 1ae14b8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

R/itemstats.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#' with the response patterns
1515
#' @param group optional grouping variable to condition on when computing
1616
#' summary information
17-
#' @param proportions logical; include response proportion information for
18-
#' each item?
17+
#' @param itemfreq character vector indicting whether to
18+
#' include item response \code{"proportions"} or \code{"counts"}
19+
#' for each item. If set to \code{'none'} then this will be omitted
1920
#' @param use_ts logical; include information that is conditional on a
2021
#' meaningful total score?
2122
#' @param ts.tables logical; include mean/sd summary information
@@ -36,6 +37,7 @@
3637
#' LSAT7full <- expand.table(LSAT7)
3738
#' head(LSAT7full)
3839
#' itemstats(LSAT7full)
40+
#' itemstats(LSAT7full, itemfreq='counts')
3941
#'
4042
#' # behaviour with missing data
4143
#' LSAT7full[1:5,1] <- NA
@@ -74,15 +76,15 @@
7476
#'
7577
itemstats <- function(data, group = NULL,
7678
use_ts=TRUE,
77-
proportions=TRUE,
79+
itemfreq="proportions",
7880
ts.tables=FALSE){
7981
data <- as.matrix(data)
8082
if(!is.null(group) && !is.factor(group)) group <- factor(group)
8183
if(!is.null(group) && !is.null(group)){
8284
groups <- levels(group)
8385
out <- lapply(groups, function(g){
8486
itemstats(data=data[group == g, , drop=FALSE], group=NULL,
85-
use_ts=use_ts, proportions=proportions,
87+
use_ts=use_ts, itemfreq=itemfreq,
8688
ts.tables=ts.tables)
8789
})
8890
names(out) <- groups
@@ -131,10 +133,12 @@ itemstats <- function(data, group = NULL,
131133

132134
ret <- list(overall=as.mirt_df(overall),
133135
itemstats=as.mirt_df(df))
134-
if(proportions){
136+
if(itemfreq == "proportions" || itemfreq == 'counts'){
135137
useNA <- ifelse(any(is.na(data)), 'always', 'ifany')
136138
props <- apply(data, 2, function(x){
137-
out <- prop.table(table(x, useNA=useNA))
139+
out <- table(x, useNA=useNA)
140+
if(itemfreq == 'proportions')
141+
out <- prop.table(out)
138142
if(useNA == 'always' && out[length(out)] == 0)
139143
out[length(out)] <- NA
140144
out
@@ -148,9 +152,9 @@ itemstats <- function(data, group = NULL,
148152
pick <- names(props[[i]])
149153
proportions[i,colnames(proportions) %in% pick] <- props[[i]]
150154
}
151-
ret$proportions <- as.mirt_df(as.data.frame(proportions))
155+
ret[[itemfreq]] <- as.mirt_df(as.data.frame(proportions))
152156
} else {
153-
ret$proportions <- as.mirt_df(as.data.frame(t(props)))
157+
ret[[itemfreq]] <- as.mirt_df(as.data.frame(t(props)))
154158
}
155159
}
156160
if(ts.tables){

man/itemstats.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)