R/prMaxSD.R

Defines functions prMaxSD

Documented in prMaxSD

#' Estimate Proportion of Observed Standard Deviation from Max Possible
#' @description
#' For a specified set of variables (with a common range), estimate the percentage
#' of response variability that the person showed from maximum possible
#' @param data Matrix to be transformed (often will need to specify subset of larger dataframe)
#' @param smin Scale minimum
#' @param smax Scale maximum
#' @details This is frequently valuable to identify people who did not
#' vary their ratings substantially - which at extreme levels is generally indicative
#' of insufficient effort responding.
#' @references Dunn, A. M., Heggestad, E. D., Shanock, L. R., & Theilgard, N. (2018). Intra-individual response variability as an indicator of insufficient effort responding: Comparison to other indicators and relationships with individual differences. Journal of Business and Psychology, 33(1), 105–121.
#' @references Wood, D., Harms, P., Lowman, G. H., & DeSimone, J. A. (2017). Response speed and response consistency as mutually validating indicators of data quality in online samples. Social Psychological and Personality Science, 8, 454–464.
#'
#' Note: prMaxSD = .25 would be observed on a 5-point scale from a person rating ALL
#' items as 50\% one number and 50\% the adjacent number (e.g., 50\% 1's and 50\% 2's, or
#' 50\% 3's and 50\% 4's).
#'     Because it seems reasonably clear that these respondents with such score variability
#' should be cut, .25 is suggested as a reasonable cut point.
#'     Note also that the code makes a minor adjustment to calculate within-person standard deviation
#' as the population estimate (using N rather than N-1) to make maximum possible = 1
#' @return estimate of the proportion of the observed standard deviation
#' of the row scores from max possible (range from 0 to 1)
#' @export
#' @examples
#' #combine with subset function to remove people with
#' #less than 30% of the maximum possible SD over this range
#' #(an indicator of invariant or insufficient effort responding)
#' datafile$prMaxSD <- prMaxSD(datafile[varSet], 1, 5)
#' subdata <- subset(datafile, prMaxSD > .25)

prMaxSD <- function(data, smin, smax, dir=1) {
  sd.p <- function(x) { sd(as.matrix(x), na.rm = T)}
  prMaxSD <- apply(data, dir, function(x) sd.p(x)*sqrt((sum(!is.na(x))-1)/sum(!is.na(x)))/((smax-smin)/2))
  return(prMaxSD)
}
funfield-lab/fancyr documentation built on Nov. 21, 2023, 2:42 p.m.