R/analyse_meta.R

#' Analyse the meta regression results
#'
#' \code{analyse_meta} Gives a dataframe with descripives of the results
#'
#' Provides the number of statistically significant results, whether negative or positive, etc.
#'
#' @param Coeff A dataframe of coefficients
#' @param T_values A dataframe of t-values
#'
#' @return A dataframe with the descriptives
#' @import dplyr
#' @importFrom stats lm coef model.frame model.matrix quantile sd
#' @importFrom utils combn
#' @export
#'
#' @examples
#' result <- meta_ols(mpg ~., data = mtcars, k = 4)
#' Coeff <- result[1]
#' T_values <- result[2]
#' analyse_meta(Coeff, T_values)
analyse_meta <- function(Coeff, T_values) {
  n = nrow(Coeff)
  Coeff <- as.data.frame(Coeff)
  T_values <- as.data.frame(T_values)
  Positive <- as.data.frame(Coeff > 0)
  Significant <- as.data.frame(abs(T_values) >=  1.985)
  PosSignificant <- as.data.frame(T_values >=  1.985)
  NegSignificant <- as.data.frame(T_values <= -1.985)
  LeftSideBoundsRange <- as.data.frame(Coeff - 2*Coeff/T_values)
  RightSideBoundsRange <- as.data.frame(Coeff + 2*Coeff/T_values)

  Datamean <- summarise_all(Coeff, funs(mean(.,na.rm=TRUE)))
  Datasd <- summarise_all(Coeff, funs(sd(.,na.rm=TRUE)))
  PercentPositive <- summarise_all(Positive, funs(mean(.,na.rm=TRUE)))
  PercentSignificant <- summarise_all(Significant, funs(mean(.,na.rm=TRUE)))
  PercentPosSignificant <- summarise_all(PosSignificant, funs(mean(.,na.rm=TRUE)))
  PercentNegSignificant <- summarise_all(NegSignificant, funs(mean(.,na.rm=TRUE)))
  strong_extreme_bound_test <- (PercentNegSignificant==1) | (PercentPosSignificant == 1)
  weak_extreme_bound_test <- (PercentNegSignificant>=0.95) | (PercentPosSignificant >= 0.95)
  left_int <- summarise_all(Coeff, funs(quantile(.,0.0025,na.rm=TRUE)))
  right_int <- summarise_all(Coeff, funs(quantile(.,0.975,na.rm=TRUE)))
  left_bound <- summarise_all(LeftSideBoundsRange, funs(min(.,na.rm=TRUE)))
  right_bound <- summarise_all(RightSideBoundsRange, funs(max(.,na.rm=TRUE)))

  Results <- rbind(Datamean, Datasd, left_int, right_int, PercentSignificant, PercentNegSignificant, PercentPosSignificant, PercentPositive, strong_extreme_bound_test, weak_extreme_bound_test)
  row.names(Results) <- c("Mean", "Standard Deviation", "Conf. int. left", "Conf. int. right","Percent Significant", "Percent Neg. Significant", "Percent Pos. Significant", "Percent Positive", "Strong extreme bounds", "weak extreme bound test")
  Results <- as.data.frame(t(Results))
  Results <- Results[order(-PercentPositive),]
  return(Results)
}
Thdegraaff/metareg documentation built on May 6, 2019, 8:02 p.m.