mattocci27 / LMAms

MIT License
0 stars 0 forks source link

apply(p_mat, 2, median) * LMA or (p_mat * LMA, 2 median) #23

Closed mattocci27 closed 1 year ago

mattocci27 commented 4 years ago

GL_LMAp %>% apply(., 2, median) is not correct because median LMAp and median LMAs cannot exist together. Using p_vec <- apply(p_mat, 2, median) is correct.

mattocci27 commented 4 years ago

Using this as get_r2_2(log(PA_LMAp), log(PA_LMAs)) doesn't make sense either.

get_r2_2 <- function(ypred, y, median = TRUE) {
  #e <- -1 * sweep(ypred, 2, y)
  var_ypred <- apply(ypred, 1, var)
  var_e <- apply(y - ypred, 1, var)
  r2 <- var_ypred / (var_ypred + var_e) 
  if (median) median(r2) else r2
}

Because y - ypred is not residual variance.

Simply checking r-value for each MCMC step might be better.

my_cor <- function(x, y, median = TRUE){
  N <- nrow(x)
  r <- numeric(N)
  for (i in 1:N) r[i] <- cor(x[i, ], y[i, ]) 
  if (median) median(r) else r
}