Package 'classicaltest'

Title: Classical Test Theory (CTT) Analysis
Description: Functions for classical test theory analysis, following methods presented by Wu et al. (2006) <doi:10.1007/978-981-10-3302-5>.
Authors: Andrés Christiansen [aut, cre]
Maintainer: Andrés Christiansen <[email protected]>
License: GPL (>= 2.0)
Version: 0.7.0
Built: 2024-11-28 06:52:49 UTC
Source: CRAN

Help Index


Classical test theory item and person statistics

Description

Calculates several item and person statistics following ctitem(), and ctperson().

Usage

classicaltest(
  x,
  key = NULL,
  categories = NULL,
  wt = NULL,
  listwise = FALSE,
  recScore = TRUE,
  administered = NULL
)

Arguments

x

a data frame or matrix. For multiple choice items, columns can be numeric or strings and keys should be provided. For polytomous items, all columns should be numeric.

key

a vector indicating the keys to score the data. If NULL items are assumed as polytomous. Default is NULL.

categories

a vector indicating all possible categories. If NULL, this vector will be created with all the non-NA values present in x. Default is NULL.

wt

a numeric vector of total weights. Default is NULL.

listwise

only consider complete data (remove rows with NAs). Defaulft is FALSE.

recScore

a logical value indicating if the total score for should be calculated based only on valid values. Thus, if TRUE: rowMeans(x,na.rm = TRUE)*apply(x,1L,function(k) sum(!is.na(k))); if FALSE: rowMeans(x,na.rm = TRUE)*ncol(x). Defaulft is TRUE. If listwise, this argument is meaningless.

administered

a logical matrix indicating which items where administered. The dimensions should be the same as x. If NULL all items are considered administered.

Value

A list with item and person statistics.

Examples

data(dichodata)
data(polydata)
data(dichokey)

# Data preparation
## Random weights creation
set.seed(1919)
wt <- sample(x = 1:4, size = nrow(dichodata), replace = TRUE)

# Item and person analysis for multiple choice items
classicaltest(x = dichodata, key = dichokey, categories = c('A','B','C','D'), wt = wt)

# Item and person analysis for polytomous items
classicaltest(x = polydata, key = NULL, wt = wt)

Scoring correct/incorrect answers

Description

Transforms a data frame or matrix with raw answers into a data frame with 1s (correct answers) and 0s (incorrect answers).

Usage

correct(x, key, navalue = NA)

Arguments

x

a data frame or matrix.

key

a vector indicating the keys to score the data.

navalue

a single value indicating the score of NAs.

Value

A data frame with 1s for correct answers and 0s for incorrect answers.

Examples

data(dichodata)
data(dichokey)

# NAs as NAs
head(dichodata)
ex1 <- correct(x = dichodata, key = dichokey, navalue = NA)
head(ex1)

# NAs as 0s
head(dichodata)
ex2 <- correct(x = dichodata, key = dichokey, navalue = 0)
head(ex2)

Classical test theory item statistics

Description

Calculates several item statistics, including: item mean, frequencies, proportions, valid proportions, and correlations between item responses and the total score.

Usage

ctitem(
  x,
  key = NULL,
  categories = NULL,
  wt = NULL,
  listwise = FALSE,
  recScore = TRUE
)

Arguments

x

a data frame or matrix. For multiple choice items, columns can be numeric or strings and keys should be provided. For polytomous items, all columns should be numeric.

key

a vector indicating the keys to score the data. If NULL items are assumed as polytomous. Default is NULL.

categories

a vector indicating all possible categories. If NULL, this vector will be created with all the non-NA values present in x. Default is NULL.

wt

a numeric vector of total weights. Default is NULL.

listwise

only consider complete data (remove rows with NAs). Defaulft is FALSE.

recScore

a logical value indicating if the total score for should be calculated based only on valid values. Thus, if TRUE: rowMeans(x,na.rm = TRUE)*apply(x,1L,function(k) sum(!is.na(k))); if FALSE: rowMeans(x,na.rm = TRUE)*ncol(x). Defaulft is TRUE. If listwise, this argument is meaningless.

Details

If keys are provided, items are assume as dichotomous and transformed into 1s and 0s, where 1s are correct answers. Then, point-biserial correlations are estimated between the item and the total score (PBtotal), the item and the score without the item (PBrest), between each response category and the total score.

If keys are not provided, data must be numeric, items are assumed as polytomous and data will not be transformed. For polytomous, Pearson's correlations are estimated between the item and the total score (PEtotal), the item and the score without the item (PErest), between each response category and the total score.

Value

A data frame with item statistics.

Examples

data(dichodata)
data(polydata)
data(dichokey)

# Data preparation
## Random weights creation
set.seed(1919)
wt <- sample(x = 1:4, size = nrow(dichodata), replace = TRUE)

# Item analysis for multiple choice items
ctitem(x = dichodata, key = dichokey, categories = c('A','B','C','D'), wt = wt)

# Item analysis for polytomous items
ctitem(x = polydata, key = NULL, wt = wt)

Classical test theory person statistics

Description

Calculates persons statistics given a data frame (or matrix) of corrected data. Including sum scores, number of administered items, number of answered items, proportion of correct items (for dichotomous data), and mean score by item (for polytomous data).

Usage

ctperson(x, administered = NULL)

Arguments

x

a data frame or matrix of corrected data (only containing 1s, 0s, and NAs).

administered

a logical matrix indicating which items where administered. The dimensions should be the same as x. If NULL all items are considered administered.

Value

A data frame with person statistics.

Examples

# Data preparation
## Corrected data
corr <- correct(x = dichodata, key = dichokey, navalue = NA)
## Random administered matrix
set.seed(1919)
admin <- sample(x = 0:1, size = nrow(corr)*ncol(corr), replace = TRUE, prob = c(.05,.95))
admin <- matrix(data = as.logical(admin),nrow = nrow(corr))
head(admin)


# Person statistics with all items administered
ex1 <- ctperson(x = corr)
head(ex1)

# Person statistics with NOT all items administered
ex2 <- ctperson(x = corr, administered = admin)
head(ex2)

Simulated multiple choice data with 1000 cases, and 20 items

Description

Simulated multiple choice data with 1000 cases, and 20 items


Keys for dichodata

Description

Keys for dichodata


Dichotomize data

Description

Converts a matrix or data frame into a dichotomized data frame. Where each possible category is assigned a 1 or a 0.

Usage

dichotomize(x, id = NULL, categories = NULL, NAasNA = TRUE, sortbyItem = FALSE)

Arguments

x

a data frame or matrix.

id

a vector of unique values indicating the ids of the cases. If NULL, an id will be created following id <- 1L:nrow(x). Default is NULL.

categories

a vector indicating all possible categories. If NULL, this vector will be created with all the non-NA values present in x. Default is NULL.

NAasNA

a logical value indicating if NAs should be kept as NAs. If FALSE, NAs will be 0s. Default is TRUE.

sortbyItem

a logical value indicating if the resulting data frame should be order by item names, on the contrary, by ids. Default is FALSE.

Value

A data frame with columns for the ids, the item names and all the possible item categories, where 1s mean the person answered that category for that item, and 0s mean the contrary.

Examples

data(dichodata)

# Dichotomize with all present categories
ex1 <- dichotomize(dichodata, categories = NULL)
head(ex1)

# Dichotomize with fixed set of categories
ex2 <- dichotomize(dichodata, categories = c('A','B','C','D'))
head(ex2)

# Dichotomize with NAs as 0s
ex3 <- dichotomize(dichodata, NAasNA = FALSE)
head(ex3)

Point-biserial correlation

Description

Estimates the point-biserial correlation coefficient between dichotomous items and the person's score.

Usage

pointbiserial(x, wt = NULL, exclude = FALSE, listwise = FALSE, recScore = TRUE)

Arguments

x

a numeric data frame or matrix containing only two categories.

wt

a numeric vector of total weights. Default is NULL.

exclude

a logical value indicating if the point-biserial correlation should be calculated excluding the item from the total score. Defaulft is FALSE.

listwise

only consider complete data (remove rows with NAs). Defaulft is FALSE.

recScore

a logical value indicating if the total score for should be calculated based only on valid values. Thus, if TRUE: rowMeans(x,na.rm = TRUE)*apply(x,1L,function(k) sum(!is.na(k))); if FALSE: rowMeans(x,na.rm = TRUE)*ncol(x). Defaulft is TRUE. If listwise, this argument is meaningless.

Value

A numeric vector with the point-biserial correlation coefficients by item.

Examples

data(dichodata)
data(dichokey)

# Data preparation
## Corrected data
corr <- correct(x = dichodata, key = dichokey, navalue = NA)
## Random weights creation
set.seed(1919)
wt <- sample(x = 1:4, size = nrow(corr), replace = TRUE)


# Correlations without weights
pointbiserial(x = corr, wt = NULL)

# Correlations with weights
pointbiserial(x = corr, wt = wt)

# Correlations if item is excluded
pointbiserial(x = corr, exclude = TRUE)

# Correlations if NAs are considered 0s (recScore)
pointbiserial(x = corr, recScore = FALSE)

# Correlations with listwise
pointbiserial(x = corr, listwise = TRUE)

Simulated polytomous items data with 1000 cases, and 20 items

Description

Simulated polytomous items data with 1000 cases, and 20 items