Zack Holden
2010-May-24 00:16 UTC
[R] retrieve path analysis coefficients (package agricolae)
Dear list, I'd like to use path.analysis in the package agricolae in batch format on many files, retrieving the path coefficients for each run and appending them to a table. I don't see any posts in the help files about this package or the path.analysis package. I've tried creating an object out of the call to path.analysis, but no matter what I try, the function automatically prints the result. I'll be grateful for any assistance. Thanks in advance, Zack [[alternative HTML version deleted]]
Peter Ehlers
2010-May-24 11:10 UTC
[R] retrieve path analysis coefficients (package agricolae)
On 2010-05-23 18:16, Zack Holden wrote:> Dear list, > I'd like to use path.analysis in the package agricolae in batch format on > many files, retrieving the path coefficients for each run and appending them > to a table. I don't see any posts in the help files about this package or > the path.analysis package. I've tried creating an object out of the call to > path.analysis, but no matter what I try, the function automatically prints > the result. I'll be grateful for any assistance. >The beauty of R is that it is open source software giving you access to the code. The function agricolae::path.analysis is very simple. Unfortunately, it doesn't return anything and just prints its results. But that's easy to fix. Here's a modified version that just removes all the printing stuff and instead returns the values of the path coefficients which you can extract with '$Coeff' (note the capital 'A' in path.Analysis): path.Analysis <- function (corr.x, corr.y) { if (ncol(corr.y) > 1) corr.y <- t(corr.y) Direct <- solve(corr.x, corr.y) n <- ncol(corr.x) Coeff <- corr.x for (i in 1:n) { for (j in 1:n) { Coeff[i, j] <- Direct[j] * corr.x[i, j] } } invisible(list('Coeff'=Coeff)) } The loops aren't really necessary, so here's a simpler version: path.Analysis <- function (corr.x, corr.y) { if (ncol(corr.y) > 1) corr.y <- t(corr.y) Direct <- solve(corr.x, corr.y) n <- ncol(corr.x) Coeff <- t(corr.x * rep(Direct, n)) invisible(list("Coeff" = Coeff)) } -Peter Ehlers> Thanks in advance, > Zack > > [[alternative HTML version deleted]] > > ______________________________________________
Reasonably Related Threads
- p-values in agricolae pearson correlation
- The 'REP' term in AMMI{agricolae}
- RV: no puedo cargar el paquete "agricolae"
- subset dataframe by rows using character vector?
- Multiple Comparisons-Kruskal-Wallis-Test: kruskal{agricolae} and kruskalmc{pgirmess} don't yield the same results although they should do (?)