getScoreFromItems: Title Function to convert a vector of item responses to a...

View source: R/getScoreFromItems.R

getScoreFromItemsR Documentation

Title Function to convert a vector of item responses to a scale/measure score

Description

Title Function to convert a vector of item responses to a scale/measure score

Usage

getScoreFromItems(
  vec,
  scoreAsMean = TRUE,
  propProrateMin = NULL,
  nProrateMin = NULL,
  k = NULL,
  checkItemScores = FALSE,
  minItemScore = NULL,
  maxItemScore = NULL
)

Arguments

vec

The item responses/scores

scoreAsMean

Score is mean of item scores (as opposed to total/sum score)

propProrateMin

Minimum proportion of missing item responses that allows prorating

nProrateMin

Minimum number of missing item responses that allows prorating

k

Optional check on the number of items

checkItemScores

logical, i.e. TRUE or FALSE, which says whether to check the item scores

minItemScore

minimum allowed item score

maxItemScore

maximum allowed item score

Value

The required score

Background

This is a very simple function designed to be used in the tidyverse dplyr function to get a single score from a set of items apply a prorating rule (which may be that prorating is not allowed) and which returns the mean of the item scores or the mean of those scores. I have put it here as I kept writing new functions to do this every time I needed one! More usefully, I have built in the prorating but perhaps most usefully of all, I have built in some sanity checks on the inputs and on the item scores.

Examples

## Not run: 
### will need tidyverse to run
library(tidyverse)

### take your data
tibData %>%
   ### need to process the data row by row,
   ### hence this rowwise() request
   rowwise() %>%
      mutate(score = getScoreFromItems(c_across(item1:item10, # declare items
                                       ### next say that the score that is wanted is mean not sum
                                                scoreAsMean = TRUE,
                                                # prorating rule: here up to one missing item,
                                                nProrateMin = 1,
                                                # optional check that number of items is correct:
                                                #  here the number is 10
                                                k = 10,
                                                # next ask the function to check the item scores
                                                checkItemScores = TRUE,
                                                # so set the minimum allowed item score: here 0
                                                minItemScore = 0,
                                                # ... and set the maximum allowed score: here 6
                                                maxItemScore = 6)) %>%
     ### now we have to shift the data out of the rowwise() grouping:
     ungroup() -> tibDataWithScores


## End(Not run)

cpsyctc/CECPfuns documentation built on April 2, 2024, 2:03 a.m.