collapse: collapses response categories

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/collapse.R

Description

Collapses response categories if cell frequencies by group are below a minimum threshold specified by minCell and returns a vector of recoded responses.

Usage

1
  collapse(resp, group, minCell)

Arguments

resp

a vector of item responses

group

a vector of group designations

minCell

a minimum cell frequency

Details

Collapses item response categories in resp if the two-way contingency table (resp x group) has cell frequencies less than the minimum cell count threshold specified by minCell.

Value

a numeric vector of the same length as resp with collapsed/recoded values.

Note

The lowest item response category/score should be coded as 1 not 0 (e.g., 1, 2, 3, 4, 5; and not 0, 1, 2, 3, 4). There must be at least two unique categories after collapsing/recoding.

Author(s)

Seung W. Choi <choi.phd@gmail.com>

See Also

recode

Examples

1
2
3
4
5
  r1 <- c(1,1,2,1,1,2,2,1,2,2,1,2,2,1,1,2,1,2,2,3,3,1,2,3)
  gr <- c(0,0,0,1,1,0,1,1,0,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1) 
  collapse(r1,gr,2) #minCell=2
  ## returns  c(1,1,2,1,1,2,2,1,2,2,1,2,2,1,1,2,1,2,2,2,2,1,2,2)
  ## response categories 2 and 3 are collapsed

Example output

Loading required package: mirt
Loading required package: stats4
Loading required package: lattice
Loading required package: rms
Loading required package: Hmisc
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package:HmiscThe following objects are masked frompackage:base:

    format.pval, units

Loading required package: SparseM

Attaching package:SparseMThe following object is masked frompackage:base:

    backsolve

 [1] 1 1 2 1 1 2 2 1 2 2 1 2 2 1 1 2 1 2 2 2 2 1 2 2

lordif documentation built on May 2, 2019, 2:13 p.m.