R/getWeights.R

Defines functions getWeights

getWeights <- function(weights, data) {
  if (!is.null(weights)) {
    if (!(weights %in% colnames(data))) {
      stop("weights not defined in dataframe data", call. = FALSE)
    }
    w <- data[[weights]]
    if (!is.numeric(w) || sum(is.na(w)) != 0 || min(w) < 0) {
      stop("weights should be a numeric vector with non-negative values", call. = FALSE)
    }
  } else {
    w <- rep(1, nrow(data))
  }
  return(w)
}

Try the LMMsolver package in your browser

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

LMMsolver documentation built on Aug. 21, 2025, 5:45 p.m.