## Setting up item names for fake data
AC_names1 <- c('CogA1', 'CogA3', 'CogC7', 'CogM9', 'CogM10', 'CogM12', 'CogV13',
'CogV15', 'CogV16', 'CogV17b', 'CogF19', 'CogF23', 'CogF24', 'CogF25',
'CogC31', 'CogC32', 'CogC33a', 'CogC33c')
AC_names2 <- c('CogQ35', 'CogQ37', 'CogQ38', 'CogQ41')
AC_names3 <- c('CogO1', 'CogO2', 'CogO3', 'CogO4')
AC_names4 <- c('CogPC1', 'CogPV1', 'CogPM1','CogPM2', 'CogPF1', 'CogPCh1', 'CogPCh2')
AC_names <- c(AC_names1, AC_names2, AC_names3, AC_names4)
itemNames <- AC_names
## Generating random item responses for 8 fake respondents
set.seed(6375309)
exampleDat <- t(replicate(8, sample(0:4, size = length(itemNames), replace = TRUE)))
## Making half of respondents missing about 10% of items,
## half missing about 50%.
miss10 <- t(replicate(4, sample(c(0, 9), prob = c(0.9, 0.1),
size = length(itemNames), replace = TRUE)))
miss50 <- t(replicate(4, sample(c(0, 9), prob = c(0.5, 0.5),
size = length(itemNames), replace = TRUE)))
missMtx <- rbind(miss10, miss50)
## Using 9 as the code for missing responses
exampleDat[missMtx == 9] <- 9
exampleDat <- as.data.frame(cbind(ID = paste0('ID', 1:8),
as.data.frame(exampleDat)))
names(exampleDat) <- c('ID', itemNames)
## Returns data frame with scale scores and with original items untouched
scoredDat <- scoreFACT_COG(exampleDat)
names(scoredDat)
scoredDat
## Returns data frame with scale scores, with the appropriate items
## reverse scored, and with item values of 8 and 9 replaced with NA.
## Also illustrates the effect of setting keepNvalid = TRUE.
scoredDat <- scoreFACT_COG(exampleDat, updateItems = TRUE, keepNvalid = TRUE)
names(scoredDat)
## Descriptives of scored scales
summary(scoredDat[, c('CogPCI', 'CogQOL', 'CogOth', 'CogPCA')])
Run the code above in your browser using DataLab