set.seed(6375309)
## Generating random item responses for 8 fake respondents
exampleDat <- t(replicate(8, sample(0:4, size = 27, 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 = 27, replace = TRUE)))
miss50 <- t(replicate(4, sample(c(0, 9), prob = c(0.5, 0.5),
size = 27, 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', 'GP1', 'GP2', 'GP3', 'GP4', 'GP5',
'GP6', 'GP7', 'GS1', 'GS2', 'GS3', 'GS4', 'GS5', 'GS6',
'GS7', 'GE1', 'GE2', 'GE3', 'GE4', 'GE5', 'GE6', 'GF1',
'GF2', 'GF3', 'GF4', 'GF5', 'GF6', 'GF7')
## Returns data frame with scale scores and with original items untouched
scoredDat <- scoreFACTG(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 <- scoreFACTG(exampleDat, updateItems = TRUE, keepNvalid = TRUE)
names(scoredDat)
## Descriptives of scored scales
summary(scoredDat[, c('PWB', 'SWB', 'EWB', 'FWB', 'FACTG')])
Run the code above in your browser using DataLab