Skip to contents

Reverse score specific items given empirical range or specific scoring range.

Usage

reverse.score(data, which, range = NULL, append = ".RS")

Arguments

data

an object of class data.frame, matrix, or table with the response patterns

which

names of items or column integer location in data that should be rescored. If missing the all columns in data will be reverse scored

range

(optional) a named list to specify the low and high score ranges. Specified names must match the names found in data, and each element of this list should contain only two values. If items specified in which are omitted from this list then the empirical min/max information will be used instead

append

character vector indicating what to append to the item names that have been rescored

Value

returns the original data object with the specified items reverse scored replacing the original scoring scheme

References

Chalmers, R., P. (2012). mirt: A Multidimensional Item Response Theory Package for the R Environment. Journal of Statistical Software, 48(6), 1-29. doi:10.18637/jss.v048.i06

Author

Phil Chalmers rphilip.chalmers@gmail.com

Examples


a <- rlnorm(20)
a[c(1,5,10)] <- -a[c(1,5,10)]
diffs <- t(apply(matrix(runif(20*4, .3, 1), 20), 1, cumsum))
diffs <- -(diffs - rowMeans(diffs))
d <- diffs + rnorm(20)
dat <- simdata(a,d,itemtype='graded', N=300)
head(dat)
#>      Item_1 Item_2 Item_3 Item_4 Item_5 Item_6 Item_7 Item_8 Item_9 Item_10
#> [1,]      4      4      4      4      2      0      0      4      0       2
#> [2,]      4      0      2      2      3      4      3      4      0       3
#> [3,]      1      0      4      1      0      4      3      3      2       0
#> [4,]      2      0      4      2      0      4      3      4      1       3
#> [5,]      0      2      4      4      0      4      0      3      3       0
#> [6,]      4      0      0      0      4      1      1      1      0       3
#>      Item_11 Item_12 Item_13 Item_14 Item_15 Item_16 Item_17 Item_18 Item_19
#> [1,]       0       0       0       0       1       0       4       0       4
#> [2,]       0       1       1       1       0       0       4       2       2
#> [3,]       0       1       2       0       4       2       4       4       4
#> [4,]       0       4       4       1       3       2       1       4       0
#> [5,]       0       0       4       0       4       4       2       4       4
#> [6,]       0       4       0       0       0       0       0       0       1
#>      Item_20
#> [1,]       0
#> [2,]       4
#> [3,]       4
#> [4,]       4
#> [5,]       4
#> [6,]       4

if (FALSE) { # \dontrun{
# fitted model has negative slopes due to flipped scoring
mod <- mirt(dat)
coef(mod, simplify=TRUE)$items
plot(mod, type = 'itemscore')
} # }

# reverse the scoring for items 1, 5, and 10 only using empirical min/max
revdat <- reverse.score(dat, c('Item_1', 'Item_5', 'Item_10'))
head(revdat)
#>      Item_1.RS Item_2 Item_3 Item_4 Item_5.RS Item_6 Item_7 Item_8 Item_9
#> [1,]         0      4      4      4         2      0      0      4      0
#> [2,]         0      0      2      2         1      4      3      4      0
#> [3,]         3      0      4      1         4      4      3      3      2
#> [4,]         2      0      4      2         4      4      3      4      1
#> [5,]         4      2      4      4         4      4      0      3      3
#> [6,]         0      0      0      0         0      1      1      1      0
#>      Item_10.RS Item_11 Item_12 Item_13 Item_14 Item_15 Item_16 Item_17 Item_18
#> [1,]          2       0       0       0       0       1       0       4       0
#> [2,]          1       0       1       1       1       0       0       4       2
#> [3,]          4       0       1       2       0       4       2       4       4
#> [4,]          1       0       4       4       1       3       2       1       4
#> [5,]          4       0       0       4       0       4       4       2       4
#> [6,]          1       0       4       0       0       0       0       0       0
#>      Item_19 Item_20
#> [1,]       4       0
#> [2,]       2       4
#> [3,]       4       4
#> [4,]       0       4
#> [5,]       4       4
#> [6,]       1       4

# compare
apply(dat[,c(1,5,10)], 2, table)
#>   Item_1 Item_5 Item_10
#> 0     65    161     114
#> 1     48     10      13
#> 2     25     10      61
#> 3     24     15      28
#> 4    138    104      84
apply(revdat[,c(1,5,10)], 2, table)
#>   Item_1.RS Item_5.RS Item_10.RS
#> 0       138       104         84
#> 1        24        15         28
#> 2        25        10         61
#> 3        48        10         13
#> 4        65       161        114

if (FALSE) { # \dontrun{
# slopes all positive now
mod2 <- mirt(revdat)
coef(mod2, simplify=TRUE)$items
plot(mod2, type = 'itemscore')
} # }

# use different empirical scoring information due to options not used
  # 0 score not observed for item 1, though should have been rescored to a 4
dat[dat[,1] == 0, 1] <- 1
table(dat[,1])
#> 
#>   1   2   3   4 
#> 113  25  24 138 

# 4 score not observed for item 5, though should have been rescored to a 0
dat[dat[,5] == 4, 5] <- 3
table(dat[,5])
#> 
#>   0   1   2   3 
#> 161  10  10 119 

# specify theoretical scoring values in the range list
revdat2 <- reverse.score(dat, c('Item_1', 'Item_5', 'Item_10'),
                              range = list(Item_1 = c(0,4), Item_5 = c(0,4)))
head(revdat2)
#>      Item_1.RS Item_2 Item_3 Item_4 Item_5.RS Item_6 Item_7 Item_8 Item_9
#> [1,]         1      4      4      4         2      0      0      4      0
#> [2,]         1      0      2      2         1      4      3      4      0
#> [3,]         4      0      4      1         4      4      3      3      2
#> [4,]         3      0      4      2         4      4      3      4      1
#> [5,]         4      2      4      4         4      4      0      3      3
#> [6,]         1      0      0      0         1      1      1      1      0
#>      Item_10.RS Item_11 Item_12 Item_13 Item_14 Item_15 Item_16 Item_17 Item_18
#> [1,]          2       0       0       0       0       1       0       4       0
#> [2,]          1       0       1       1       1       0       0       4       2
#> [3,]          4       0       1       2       0       4       2       4       4
#> [4,]          1       0       4       4       1       3       2       1       4
#> [5,]          4       0       0       4       0       4       4       2       4
#> [6,]          1       0       4       0       0       0       0       0       0
#>      Item_19 Item_20
#> [1,]       4       0
#> [2,]       2       4
#> [3,]       4       4
#> [4,]       0       4
#> [5,]       4       4
#> [6,]       1       4
table(dat[,1])
#> 
#>   1   2   3   4 
#> 113  25  24 138 
table(revdat2[,1])
#> 
#>   1   2   3   4 
#> 138  24  25 113 

table(dat[,5])
#> 
#>   0   1   2   3 
#> 161  10  10 119 
table(revdat2[,5])
#> 
#>   1   2   3   4 
#> 119  10  10 161