R/meechua_reg.R

Defines functions meechua_reg

Documented in meechua_reg

################## # regression analysis for each mu ############################
#' @export
#' @import stats
### data must be ordered by mu ###


meechua_reg <- function(x) {
  models <- lapply(split(x, x$mu), function(df) lm(after ~ before, data = df))
  mod_coef <- do.call(rbind, lapply(models, coef))
  mod_coef <- as.data.frame(mod_coef, stringsAsFactors = FALSE)
  
  results <- do.call(rbind, lapply(models, function(i) coef(summary(i))))
  se <- results[, "Std. Error"]
  se_after <- se[seq(1, length(se), 2)]
  
  # Direkte Rückgabe der Ergebnisse
  return(list(models = models, mod_coef = mod_coef, se_after = se_after))
}

Try the regtomean package in your browser

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

regtomean documentation built on April 4, 2025, 2:08 a.m.