diff --git a/R/mafa.R b/R/mafa.R index 02b4598a6f069ccdf4eabf1e7ddd5122c07620bb..f66191153a35830ee69cbbcc0472517bf987555c 100644 --- a/R/mafa.R +++ b/R/mafa.R @@ -21,10 +21,10 @@ #' @seealso \url{https://doi.org/10.1051/alr/2009020} #' @examples #' df <- data.frame(variable1variabl = 1:20, variable2= rnorm(20, 100, 30), variable3 = 1:20 + rnorm(20)) -#' mafa(x = df, time = 1981:2000, nreal = 10) -#' df <- matrix(rnorm(100), ncol = 5) -#' colnames(df) <- letters[1:5] -#' mafa(df) +#' mafa(x = df, time = 1981:2000) +#' df <- matrix(rnorm(1000), ncol = 50) +#' colnames(df) <- paste0(letters[1:25], rep(1:2,each = 25)) +#' mafa(df, contr_var = 10) #' mafa <- function(x, time = NULL, nreal = 1000, nmafs = 3, seed = NULL, contr_var = NULL){ @@ -123,12 +123,12 @@ mafa <- function(x, time = NULL, nreal = 1000, nmafs = 3, seed = NULL, contr_var # choose top contr_var choose <- rev(order(abs(maf_rot)))[1:contr_var] maf_rot <- maf_rot[choose] - vars <- vars[choose] + vars_j <- vars[choose] # sort ord <- order(maf_rot) maf_rot <- maf_rot[ord] - vars <- vars[ord] - nvc <- length(vars) + vars_j <- vars_j[ord] + nvc <- length(vars_j) mr_pos <- which(maf_rot > 0) mr_neg <- which(maf_rot < 0) fac <- 2 @@ -141,10 +141,10 @@ mafa <- function(x, time = NULL, nreal = 1000, nmafs = 3, seed = NULL, contr_var Col <- rep(1, nvc) Col[seq(1, nvc, 1)[abs(maf_rot) == max(abs(maf_rot))]] <- 3 if (length(mr_pos) > 0) { - text(maf_rot[mr_pos], seq(0.5, nvc-.5, 1)[mr_pos], vars[mr_pos], cex = .9, col = Col[mr_pos], pos = 4) + text(maf_rot[mr_pos], seq(0.5, nvc-.5, 1)[mr_pos], vars_j[mr_pos], cex = .9, col = Col[mr_pos], pos = 4) } if (length(mr_neg) > 0) { - text(maf_rot[mr_neg], seq(0.5, nvc-.5, 1)[mr_neg], vars[mr_neg], cex = .9, col = Col[mr_neg], pos = 2) + text(maf_rot[mr_neg], seq(0.5, nvc-.5, 1)[mr_neg], vars_j[mr_neg], cex = .9, col = Col[mr_neg], pos = 2) } diff --git a/man/mafa.Rd b/man/mafa.Rd index d2e95626d0ab99b70f69817c095bd1b4ea07f355..2080b4c97be1727cc15af65d2021d4bc783a9c78 100644 --- a/man/mafa.Rd +++ b/man/mafa.Rd @@ -31,11 +31,11 @@ the part of the variables which is the most continuous in time. The function for this code is adopted from Wollez et al. 2009 (\url{https://doi.org/10.1051/alr/2009020}) } \examples{ -df <- data.frame(variable1 = 1:20, variable2= rnorm(20, 100, 30), variable3 = 1:20 + rnorm(20)) +df <- data.frame(variable1variabl = 1:20, variable2= rnorm(20, 100, 30), variable3 = 1:20 + rnorm(20)) mafa(x = df, time = 1981:2000) -df <- matrix(rnorm(100), ncol = 5) -colnames(df) <- letters[1:5] -mafa(df) +df <- matrix(rnorm(1000), ncol = 50) +colnames(df) <- paste0(letters[1:25], rep(1:2,each = 25)) +mafa(df, contr_var = 10) } \seealso{