R/calculate_R2.R

Defines functions r2_calc

Documented in r2_calc

#' Extract R^2 from a linear model
#' 
#' @description Calculate the adjusted r-squared from a linear model given
#' a dataframe and formula
#' 
#' @param data The data frame to perform the calculation on
#' @param formula A formula for the model
#' 
#' @return A scalar numeric representing the adjusted r-squared for the model
#' 
#' @author Sam Levin
#' 
#' @importFrom stats as.formula lm
#' @export
#' 

r2_calc <- function(data, formula){
  
  mod <- summary(lm(as.formula(formula), data = data))
  
  out <- mod$adj.r.squared
  
  return(out)
}
levisc8/Fun_Phylo_Package documentation built on June 2, 2020, 8:41 a.m.