Closed Censkey closed 2 years ago
Hi!
If you subset the data, I strongly suggest using droplevels()
. See what the 'note' of droplevels documentation says "Notice that subsetting does not in general drop unused levels"
library(metan)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
#> |=========================================================|
#> | Multi-Environment Trial Analysis (metan) v1.17.0 |
#> | Author: Tiago Olivoto |
#> | Type 'citation('metan')' to know how to cite metan |
#> | Type 'vignette('metan_start')' for a short tutorial |
#> | Visit 'https://bit.ly/pkgmetan' for a complete tutorial |
#> |=========================================================|
sub1 <- data_ge2[data_ge2$ENV != "A1", ]
levels(sub1$ENV)
#> [1] "A1" "A2" "A3" "A4"
# drop unused levels
sub2 <- droplevels(data_ge2[data_ge2$ENV != "A1", ])
levels(sub2$ENV)
#> [1] "A2" "A3" "A4"
Since here the function gets the number of environments, the results will change.
Since there is no a clear bug, I'm closing this now. Hope it helps!
Created on 2022-10-01 with reprex v2.0.2
Hi, when calculating shukla stability using the Shukla() function, I ran into a problem where the results change depending on the subset of my data. I'm not sure if it's desired to take the initial number of levels from the data frame, as in line 55 with as.factor(), or if there's something wrong with using factor() instead to solve this problem?
https://github.com/TiagoOlivoto/metan/blob/526b4625621f8cae074bc9b068eb6d1a7ae1c070/R/Shukla.R#L55
Here is a reproducible example with the provided sample data:
And here the results: