R/GStudyPerType.R

Defines functions GStudyPerType

Documented in GStudyPerType

#' GStudyPerType: This function is mainly used within calculateVarCov.R, but can be executed on its own to determine the reliability coefficient and SEM for a dataset with a single type of assessment.
#'
#' @param dataPerAssessmentType A dataframe containing columns ID, Type, Score (numeric), with only one value in column Type
#'
#' @return A matrix presenting the observerd varianced and residual, number of ID's and the percentage of the total variance for each group
#' @export

GStudyPerType <- function(dataPerAssessmentType) {
  checkDatasets(dataPerAssessmentType)

  myformula = "Score ~ 1 + (1|ID)"  #a two-sided linear formula object describing both the fixed-effects and random-effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Random-effects terms are distinguished by vertical bars (|) separating expressions for design matrices from  grouping factors. Two vertical bars (||) can be used to specify multiple uncorrelated random effects for the same grouping variable

  fit <- lme4::lmer(formula=myformula, data=dataPerAssessmentType)
  summary(fit)
  sum <- summary(fit)
  ngrps <- as.data.frame(sum$ngrps)
  ngrps$grp <- row.names(ngrps)
  colnames(ngrps) <- c("n","grp")

  var1 = var2 = sdcor = NULL
  varcor <- as.data.frame(lme4::VarCorr(fit)) %>% dplyr::left_join(ngrps, by=c("grp"))
  totvar <- sum(varcor$vcov)
  varcor$perc <- 100*varcor$vcov/totvar
  res <- varcor %>% dplyr::select(-var1, -var2, -sdcor);
  rownames(res) <- res$grp

  return(res)
}

Try the compositeReliabilityInNestedDesigns package in your browser

Any scripts or data that you put into this service are public.

compositeReliabilityInNestedDesigns documentation built on Sept. 22, 2024, 1:06 a.m.