microeco icon indicating copy to clipboard operation
microeco copied to clipboard

ISSUE to plot the results of Trans$null model class

Open CYBERBOY1210 opened this issue 1 year ago • 7 comments

Hi there. I am trying to add betaNRI matrix to my beta_diversity list, and plot the results. However when I try to run this part of the code: g1 <- t2$plot_group_distance(distance_pair_stat = TRUE), I'm getting the following message: "The ordered groups are Disturbed Undisturbed ... Error in [.data.frame(use_data, , group) : undefined columns selected" I have been dealing with this issue for several days and have been trying to run the code with different datasets...but I get the same error. This is the complete code I ran:

dataset$beta_diversity[["betaNRI"]] <- t1$res_ses_betampd

create trans_beta class, use measure "betaNRI"

t2 <- trans_beta$new(dataset = dataset, group = "Type", measure = "betaNRI")

transform the distance for each group

t2$cal_group_distance()

plot the results

g1 <- t2$plot_group_distance(distance_pair_stat = TRUE) g1 + geom_hline(yintercept = -2, linetype = 2) + geom_hline(yintercept = 2, linetype = 2)

I'm not an expert in R...Any ideas?

CYBERBOY1210 avatar Mar 01 '23 11:03 CYBERBOY1210

Hi. Which version are you using? The distance_pair_stat parameter in plot_group_distance has been deprecated. The function in the current package v0.14.1 is very different from older usage. Please first update the package. Then check this part in the tutorial again (https://chiliubio.github.io/microeco_tutorial/diversity-based-class.html#trans_beta-class) or see the help document with the command ?trans_beta.

ChiLiubio avatar Mar 02 '23 01:03 ChiLiubio

Hi. Thank you for getting back to me. I though there was a sort of bug with the code. I was using an older version but I updated it to v0.14.1. I am still getting the same error when I run the code: g1 <- t2$plot_group_distance(distance_pair_stat = TRUE). I will go over the ?trans_beta command, but if you have any other suggestions please let me know.

CYBERBOY1210 avatar Mar 02 '23 11:03 CYBERBOY1210

Hi. The parameter distance_pair_stat has been deprecated. Please delete it in your code. If there is still an issue, please paste your script with the example dataset so that I can reproduce your issue.

ChiLiubio avatar Mar 03 '23 01:03 ChiLiubio

Hi, I did that, but when I get rid of the "distance_pair_stat", the code is not working either. I have been using the code from the Microeco tutorial version v0.14.1. Below is the chunk of code I used with the sample "dataset"

t1 <- trans_nullmodel$new(dataset, filter_thres = 0.0005, add_data = sample_info_16S)

t1$cal_ses_betampd(runs=500, abundance.weighted = TRUE)

dataset$beta_diversity[["betaNRI"]] <- t1$res_ses_betampd

t2 <- trans_beta$new(dataset = dataset, group = "Type", measure = "betaNRI")

t2$cal_group_distance()

g1 <- t2$plot_group_distance(distance_pair_stat = TRUE) g1 + geom_hline(yintercept = -2, linetype = 2) + geom_hline(yintercept = 2, linetype = 2)

CYBERBOY1210 avatar Mar 03 '23 11:03 CYBERBOY1210

Hi. Sorry. It is a bug. The reason is plot_group_distance can not recognize the group parameter passing when cal_group_distance_diff function is not used. To temporarily resolve this, please use this:

library(ggplot2)
library(microeco)
t1 <- trans_nullmodel$new(dataset, filter_thres = 0.0005, add_data = sample_info_16S)
t1$cal_ses_betampd(runs=500, abundance.weighted = TRUE)
dataset$beta_diversity[["betaNRI"]] <- t1$res_ses_betampd
t2 <- trans_beta$new(dataset = dataset, group = "Type", measure = "betaNRI")
t2$cal_group_distance()
t2$cal_group_distance_diff(method = "anova")
g1 <- t2$plot_group_distance(distance_pair_stat = TRUE)
g1 + geom_hline(yintercept = -2, linetype = 2) + geom_hline(yintercept = 2, linetype = 2)

I have fixed this and updated the package in github. If you do not want to change your code, you can reinstall the package from github and try again. The CRAN version will be later updated till the next release.

Best, Chi

ChiLiubio avatar Mar 04 '23 03:03 ChiLiubio

Also thank you for letting me know the tutorial is a little behind for the current package version.

ChiLiubio avatar Mar 04 '23 05:03 ChiLiubio

Hi, Chi. I used the modified code and it works! Thank you so much for your help and disposition.

Jay

CYBERBOY1210 avatar Mar 04 '23 19:03 CYBERBOY1210