R/RV_Cor.R

Defines functions RV_COR

Documented in RV_COR

#' Computed the RV coefficient between the metrics.
#'
#' `RV_COR()` Return matrix of correlation between all metrics.
#'
#' This function is meant to be used with the tab generated by formultivariate()
#' The RV coefficient is meant to compute the correlation between two tabs.
#' In this case metric's values at each scale are considered as tab. So a RV coefficient is computed
#' for each pairwise metrics with an associeted p-value.
#' @param Varia_paysage_multi Tab generated by formodel()
#'
#' @param dist Vector of scales you choosed during you analusis in Chloe
#' @param metrics Vector of  metrics  you choosed in Chloe during your analysis in Chloe
#' @return Return matrix of correlation between all metrics.
#' @export
RV_COR=function(Varia_paysage_multi,metrics,dist){
  coefRV=matrix(ncol=length(metrics),nrow=length(metrics))
  coefRV[lower.tri(coefRV)]=2
  diag(coefRV)=2
  pvalue=matrix(ncol=length(metrics),nrow=length(metrics))
  colnames(coefRV) = row.names(coefRV) = metrics
  colnames(pvalue) = row.names(pvalue) = metrics

  pb <- txtProgressBar(min = 0, max = length(metrics), style = 3)
  rep=0
  for (i in metrics) {
    Sys.sleep(0.1)
    rep=rep+1
    setTxtProgressBar(pb, rep)
    for (j in metrics) {
      if(is.na(coefRV[i,j])){next}
      temp=coeffRV(Varia_paysage_multi[Varia_paysage_multi$Metric==i,4:(3+length(scales))],
                   Varia_paysage_multi[Varia_paysage_multi$Metric==j,4:(3+length(scales))])
      coefRV[i,j]=temp$rv
      pvalue[i,j]=temp$p.value

    }
  }
  coefRV[upper.tri(coefRV)]=t(coefRV)[upper.tri(coefRV)]
  diag(coefRV)=1
  pvalue[upper.tri(pvalue)]=t(pvalue)[upper.tri(pvalue)]
  return(list(coefRV,pvalue))
}
Pintademijote/multipack documentation built on Sept. 24, 2019, 7:54 a.m.