R/calculate_wgt_corr.R

Defines functions calculate_wgt_cor

Documented in calculate_wgt_cor

#------------------------------------------------------------------------------

#' The function calculates a weighted Pearson correlation coefficient between
#' variable A and B using \code{\link{wtd.cor}}.
#'
#' @title Calculate weighted Pearson correlation coefficient
#'
#' @param d.sub a dataframe with data.
#'
#' @param x character string of the name of variable A.
#'
#' @param y character string of the name of variable B.
#'
#' @importFrom weights wtd.cor
#'
#' @return the numeric value of the correlation coefficient.
#'
#' @export


calculate_wgt_cor <- function(d.sub, x, y){

  round(wtd.cor(d.sub[,x], d.sub[,y], weight = d.sub[,"new_weight"])[,"correlation"], 3)

}
lorecatta/DENVfoiMap documentation built on April 1, 2022, 4:05 p.m.