Posts

Showing posts with the label Regression analysis

A simple function to create a regression output in R

Image
There are several ways to create an output of regression analysis in R. This is a simple custom made function. # Clear all rm(list=ls()) # Libraries library(QuantPsyc) # Regression summary function table_lm <- function(lm_object, digit_rounding){   summary_lmobject = summary(lm_object)   df_output = data.frame(   predictors = names(lm_object$coefficients),   beta = round(as.numeric(summary_lmobject$coefficients[,1]), digit_rounding),   SE = round(as.numeric(summary_lmobject$coefficients[,2]), digit_rounding),   SE95ci_low = round(as.numeric(confint(lm_object, level = 0.95)[,1]),digit_rounding),   SE95ci_high = round(as.numeric(confint(lm_object, level = 0.95)[,2]),digit_rounding),   stdbeta = c(NA,round(lm.beta(lm_object), digit_rounding)),   ttest = round(summary_lmobject$coefficients[,3], digit_rounding),   pvalues = sapply(as.numeric(summary_lmobject$coefficients[,4]),             ...