R/model_sig.R

Defines functions model_sig

Documented in model_sig

#' model_sig
#'
#' This function return TRUE if you model have all
#' coefficients significatives and FALSE otherwise.
#'
#' @param model R model object.
#' @param p_value p_value.
#' @param ignore_intercept_sig If TRUE function will ignore intercept significance.
#' @param one_cat_sig If TRUE function will consider significant models with al least one cat of the vars significative.
#' @param trim_chars Number of chars of name vars  the function will trim.
#' @return TRUE or FALSE
#' @export
model_sig = function(model,
                     one_cat_sig = FALSE,
                     p_value=0.05,
                     ignore_intercept_sig = TRUE,
                     trim_chars = 2){

  df = data.frame(coef(summary(model)))
  names(df)[names(df) == 'Pr...z..'] = 'x'

  if(ignore_intercept_sig) df = df[-1,]
  if(one_cat_sig) df = aggregate(df$x, by=list(strtrim(x = rownames(df),width = nchar(rownames(df)) - trim_chars)), FUN=min)

  ifelse(sum(df$x>p_value),return(FALSE),return(TRUE))
}
jrgazola/stepKS documentation built on March 22, 2022, 12:06 a.m.