reverse.score {mirt} | R Documentation |
Reverse score specific items given empirical range or specific scoring range.
reverse.score(data, which, range = NULL, append = ".RS")
data |
an object of class |
which |
names of items in |
range |
(optional) a named |
append |
character vector indicating what to append to the item names that have been rescored |
returns the original data
object with the specified
items reverse scored replacing the original scoring scheme
Phil Chalmers rphilip.chalmers@gmail.com
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
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 2 3 2 3 3 4 0
## [2,] 0 4 1 2 0 4 0 4 1 0
## [3,] 4 0 0 0 4 2 1 0 0 2
## [4,] 4 0 4 4 0 4 3 0 1 4
## [5,] 0 4 4 2 0 0 1 2 0 0
## [6,] 1 4 1 4 0 2 4 4 4 0
## Item_11 Item_12 Item_13 Item_14 Item_15 Item_16 Item_17 Item_18 Item_19
## [1,] 1 3 2 4 4 4 2 2 4
## [2,] 4 4 4 4 4 4 3 4 4
## [3,] 0 1 1 0 0 0 0 0 0
## [4,] 0 2 0 2 0 2 2 4 3
## [5,] 0 3 0 0 0 3 0 1 0
## [6,] 4 4 4 4 4 4 4 4 2
## Item_20
## [1,] 0
## [2,] 1
## [3,] 4
## [4,] 0
## [5,] 4
## [6,] 0
## No test:
# fitted model has negative slopes due to flipped scoring
mod <- mirt(dat)
coef(mod, simplify=TRUE)$items
## a1 d1 d2 d3 d4
## Item_1 -1.1971993 2.4505365 1.9263151 1.4606155 0.8114021
## Item_2 4.3503412 2.6934596 2.2774887 1.8115126 1.1388076
## Item_3 1.0008198 0.3862293 -0.1650475 -0.8048182 -1.6233906
## Item_4 0.3206388 1.2104601 0.4854225 -0.5934311 -1.3234766
## Item_5 -1.5589825 -1.1394780 -1.4306745 -1.7945719 -2.2492976
## Item_6 0.6137197 0.7141486 0.3664111 -0.6271019 -1.2989834
## Item_7 1.1734689 1.2503101 0.3786926 -0.1346547 -1.1618626
## Item_8 2.0499334 -0.2838143 -0.7547274 -1.3703709 -2.0137720
## Item_9 0.3289672 0.1644043 -0.3184516 -0.6211153 -1.5965036
## Item_10 -4.4163824 -0.7620607 -1.0802193 -2.2496601 -2.7851461
## Item_11 4.6796412 0.6603322 -0.5033574 -0.8589911 -1.6849209
## Item_12 0.5517480 2.1440011 1.4401115 0.9022295 0.3022269
## Item_13 2.1354955 1.3599318 0.8523544 0.3119059 -0.5261526
## Item_14 2.9436105 1.5434941 0.6669434 0.0276986 -0.5084368
## Item_15 5.1213884 2.4191791 1.5264767 1.0144795 0.2282623
## Item_16 3.0164044 3.4236137 2.3210370 1.5101707 0.6893375
## Item_17 1.4167408 0.9178010 0.6648400 -0.3986223 -1.1565179
## Item_18 0.7232597 1.2447809 0.2856159 -0.3427801 -1.1325728
## Item_19 1.4723959 0.7637786 0.6056608 -0.2822496 -0.6061917
## Item_20 0.1715745 0.8679492 0.2411585 -0.3544034 -0.6842691
plot(mod, type = 'itemscore')
## End(No test)
# 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 2 1 2 3 3 4
## [2,] 4 4 1 2 4 4 0 4 1
## [3,] 0 0 0 0 0 2 1 0 0
## [4,] 0 0 4 4 4 4 3 0 1
## [5,] 4 4 4 2 4 0 1 2 0
## [6,] 3 4 1 4 4 2 4 4 4
## Item_10.RS Item_11 Item_12 Item_13 Item_14 Item_15 Item_16 Item_17 Item_18
## [1,] 4 1 3 2 4 4 4 2 2
## [2,] 4 4 4 4 4 4 4 3 4
## [3,] 2 0 1 1 0 0 0 0 0
## [4,] 0 0 2 0 2 0 2 2 4
## [5,] 4 0 3 0 0 0 3 0 1
## [6,] 4 4 4 4 4 4 4 4 4
## Item_19 Item_20
## [1,] 4 0
## [2,] 4 1
## [3,] 0 4
## [4,] 3 0
## [5,] 0 4
## [6,] 2 0
# compare
apply(dat[,c(1,5,10)], 2, table)
## Item_1 Item_5 Item_10
## 0 36 206 168
## 1 16 13 8
## 2 18 15 29
## 3 32 16 12
## 4 198 50 83
apply(revdat[,c(1,5,10)], 2, table)
## Item_1.RS Item_5.RS Item_10.RS
## 0 198 50 83
## 1 32 16 12
## 2 18 15 29
## 3 16 13 8
## 4 36 206 168
## No test:
# slopes all positive now
mod2 <- mirt(revdat)
coef(mod2, simplify=TRUE)$items
## a1 d1 d2 d3 d4
## Item_1.RS 1.1968871 -0.8103669 -1.4595396 -1.92523612 -2.4494252
## Item_2 4.3489638 2.6971728 2.2812725 1.81532457 1.1425781
## Item_3 1.0006132 0.3870568 -0.1641429 -0.80398004 -1.6224944
## Item_4 0.3205880 1.2107280 0.4856952 -0.59315493 -1.3232048
## Item_5.RS 1.5588926 2.2508010 1.7958831 1.43211785 1.1409167
## Item_6 0.6136151 0.7146693 0.3669349 -0.62657248 -1.2984545
## Item_7 1.1732822 1.2513189 0.3797120 -0.13363671 -1.1608578
## Item_8 2.0493773 -0.2820196 -0.7528740 -1.36853441 -2.0119053
## Item_9 0.3289077 0.1647082 -0.3181783 -0.62085822 -1.5962104
## Item_10.RS 4.4152574 2.7890491 2.2536347 1.08421037 0.7660751
## Item_11 4.6780441 0.6645410 -0.4989524 -0.85456721 -1.6805246
## Item_12 0.5516970 2.1445027 1.4405795 0.90272416 0.3026851
## Item_13 2.1350953 1.3618561 0.8542508 0.31383673 -0.5242754
## Item_14 2.9430535 1.5461078 0.6696386 0.03038757 -0.5057599
## Item_15 5.1189698 2.4233165 1.5308932 1.01898898 0.2328142
## Item_16 3.0160892 3.4263360 2.3238349 1.51294951 0.6920508
## Item_17 1.4164935 0.9190633 0.6660691 -0.39738177 -1.1552932
## Item_18 0.7231101 1.2453804 0.2862299 -0.34215613 -1.1319459
## Item_19 1.4721421 0.7650922 0.6069535 -0.28095673 -0.6048962
## Item_20 0.1715480 0.8680933 0.2413077 -0.35426285 -0.6841202
plot(mod2, type = 'itemscore')
## End(No test)
# 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
## 52 18 32 198
# 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
## 206 13 15 66
# 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,] 0 4 4 2 1 2 3 3 4
## [2,] 3 4 1 2 4 4 0 4 1
## [3,] 0 0 0 0 1 2 1 0 0
## [4,] 0 0 4 4 4 4 3 0 1
## [5,] 3 4 4 2 4 0 1 2 0
## [6,] 3 4 1 4 4 2 4 4 4
## Item_10.RS Item_11 Item_12 Item_13 Item_14 Item_15 Item_16 Item_17 Item_18
## [1,] 4 1 3 2 4 4 4 2 2
## [2,] 4 4 4 4 4 4 4 3 4
## [3,] 2 0 1 1 0 0 0 0 0
## [4,] 0 0 2 0 2 0 2 2 4
## [5,] 4 0 3 0 0 0 3 0 1
## [6,] 4 4 4 4 4 4 4 4 4
## Item_19 Item_20
## [1,] 4 0
## [2,] 4 1
## [3,] 0 4
## [4,] 3 0
## [5,] 0 4
## [6,] 2 0
table(dat[,1])
##
## 1 2 3 4
## 52 18 32 198
table(revdat2[,1])
##
## 0 1 2 3
## 198 32 18 52
table(dat[,5])
##
## 0 1 2 3
## 206 13 15 66
table(revdat2[,5])
##
## 1 2 3 4
## 66 15 13 206