Comments (7)
Dear @drschowdary , thanks for reporting this issue. This probably occurs because the correlation matrix between predictors (cor_mat) is not positive definite. Could you please provide a reproducible example? See how to use reprex to do that (https://reprex.tidyverse.org/)
Here, I show a similar error, forcing an exactly singular matrix (determinant = 0)
library(metan)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
#> |=========================================================|
#> | Multi-Environment Trial Analysis (metan) v1.16.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 |
#> |=========================================================|
mat <-
data_ge2 %>%
mutate(EH2 = EH) %>% # force a perfectly correlated predictor
select_numeric_cols() %>%
corr_coef()
pcoeff <- path_coeff_mat(mat$cor, resp = EP)
#> Error in solve.default(cor.x, cor.y): Lapack routine dgesv: system is exactly singular: U[15,15] = 0
Created on 2021-12-27 by the reprex package (v2.0.1)
from metan.
Since this clearly is not a bug but an issue related to the data, I'm closing this issue. Feel free to re-open it if necessary.
from metan.
from metan.
@drschowdary, path analysis is done in GENES probably because GENES uses a different method of matrix inversion, which returns an approximate inverse of a matrix even when it is singular (see an example in metan at https://tiagoolivoto.github.io/metan/reference/solve_svd.html). I strongly suggest you check the multicollinearity of the matrix of predictor traits (use metan::colindiag()), because your path coefficients might be highly biased.
from metan.
from metan.
@drschowdary, I just changed the method of matrix inversion so that a pseudo-inverse is computed even with a singular matrix. A warning will alert you about this problem. To get this new feature, install the development version of metan with
devtools::install_github("TiagoOlivoto/metan")
After installing the development version, you'll be able to run the following examples. There are two main ways of dealing with multicollinearity (see our paper for more info). The first (and that I'd suggest) is removing the traits that are being the main cause of the problem. The second is including a correction factor (k) in the diagonal of the correlation matrix.
library(metan)
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
#> |=========================================================|
#> | Multi-Environment Trial Analysis (metan) v1.16.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 |
#> |=========================================================|
df_colinear <-
data_ge2 %>%
select(PH, EP, KW, NKE) %>%
mutate(PH2 = PH)
# now it runs with a warning
pc1 <- path_coeff(df_colinear, resp = KW)
#> Warning: System is computationally singular. Check the collinearity of
#> predictors with `metan::colindiag()`.
#> Severe multicollinearity.
#> Condition Number: 50796137447998448
#> Consider using a correction factor with 'correction' argument.
#> Consider identifying collinear traits with `non_collinear_vars()`
plot(pc1)
# include a correction factor, say, 0.05
pc2 <- path_coeff(df_colinear, resp = KW, correction = 0.05)
#> Weak multicollinearity.
#> Condition Number: 56.782
#> You will probably have path coefficients close to being unbiased.
plot(pc2)
# identifying colinear traits
diagnosis <- colindiag(df_colinear)
print(diagnosis)
#> Severe multicollinearity in the matrix! Pay attention on the variables listed bellow
#> CN = 9413786837639034
#> Matrix determinant: 0
#> Largest correlation: PH x PH2 = 1
#> Smallest correlation: EP x NKE = 0.233
#> Number of VIFs > 10: 0
#> Number of correlations with r >= |0.8|: 1
#> Variables with largest weight in the last eigenvalues:
#> PH2 > PH > KW > NKE > EP
# removing the collinear trait PH2
# option 1
pc3 <-
df_colinear %>%
remove_cols(PH2) %>%
path_coeff(resp = KW)
#> Weak multicollinearity.
#> Condition Number: 6.119
#> You will probably have path coefficients close to being unbiased.
plot(pc3)
# option 2
pc4 <- path_coeff(df_colinear, resp = KW, pred = -PH2)
#> Weak multicollinearity.
#> Condition Number: 6.119
#> You will probably have path coefficients close to being unbiased.
plot(pc4)
Created on 2021-12-30 by the reprex package (v2.0.1)
from metan.
from metan.
Related Issues (20)
- Release metan 1.16.0 HOT 1
- Problem with ge_stats HOT 3
- AMMI Analysis HOT 2
- Shukla Stablility with wrong length of levels HOT 1
- print_table(.) : could not find function "print_table" HOT 1
- MGIDI selection differential is false if averaged data is negative HOT 2
- error when I run ge_stat() code of metan package HOT 8
- Problem with plot.gge or plot function HOT 2
- Error in corr_coef(data, ..., type = c("linear", "partial"), method = c("pearson", : could not find function "corr_coef" HOT 2
- Error in path_coeff(datt, resp = SYPPI) : could not find function "path_coeff" HOT 2
- Same code of "metan" running on on one dataset, but not on similar second dataset HOT 2
- Inclusion of covariate to dependent trait while calculating BLUP values
- Inclusion of covariate to dependent trait while calculating BLUP values HOT 1
- How to remove outliers in METAN HOT 1
- Hello HOT 2
- metan temporarily out of CRAN HOT 1
- Mislabeling of ENV and GEN in Which Won Where Biplot HOT 6
- rep and block arguments for gge HOT 1
- problem in running your example code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metan.