correlation matrices
Closed this issue · 0 comments
Erin-Rooney commented
This is the code that I'm worried about. I am not sure if it gave me reliable correlation matrices.
This is the page I used. I'm having trouble figuring out if I did a pearson correlation. Or maybe I didn't complete the correlation matrix?
http://www.sthda.com/english/wiki/correlation-matrix-a-quick-start-guide-to-analyze-format-and-visualize-a-correlation-matrix-using-r-software
WyoP/code/1-dataprocessing-ghP.R
Lines 78 to 150 in af2a5a4
#correlation matrix for all cover crops (no fallow) no caco3/inorganic c | |
corr_data = | |
pall2 %>% | |
filter(ctrt != 'Fallow') %>% | |
select(cbio, wbio, pbic_percbio, amac_percbio, unavp_percbio, | |
porg_percbio, amm_percbio, nit_percbio, | |
pmn_percbio, pmc_percbio) %>% | |
na.omit() %>% | |
force() | |
matrix1 <- rcorr(as.matrix(corr_data)) | |
matrix1 | |
# Extract the correlation coefficients | |
corrpercbio_r <- matrix1$r | |
# Extract p-values | |
corrpercbio_p <- matrix1$P | |
write.csv(corrpercbio_r, "corrpercbio_r.csv", row.names = TRUE) | |
write.csv(corrpercbio_p, "corrpercbio_p.csv", row.names = TRUE) | |
#correlation matrix for all cover crops with caco3/inorganic c (time1 only) | |
corr_data2 = | |
pall2 %>% | |
filter(time == '1') %>% | |
select(cbio, wbio, pbic_percbio, amac_percbio, unavp_percbio, | |
porg_percbio, inorgcarbon_percbio, amm_percbio, nit_percbio, | |
pmn_percbio, pmc_percbio) %>% | |
force() | |
matrix2 <- rcorr(as.matrix(corr_data2)) | |
matrix2 | |
##rcorr(matrix2, type = c("pearson")) | |
# Extract the correlation coefficients | |
corrpercbiocaco3_r <- matrix2$r | |
# Extract p-values | |
corrpercbiocaco3_p <- matrix2$P | |
write.csv(corrpercbiocaco3_r, "corrpercbiocaco3_r.csv", row.names = TRUE) | |
write.csv(corrpercbiocaco3_p, "corrpercbiocaco3_p.csv", row.names = TRUE) | |
#correlation matrix no standardization, no caco3 | |
corr_data3 = | |
pall2 %>% | |
#filter(time == '1') %>% | |
select(cbio, wbio, pbic, amac, unavp, | |
porg, amm, nit, | |
pmn, pmc) %>% | |
force() | |
matrix3 <- rcorr(as.matrix(corr_data3)) | |
matrix3 | |
# Extract the correlation coefficients | |
corr_r <- matrix3$r | |
# Extract p-values | |
corr_p <- matrix3$P | |
write.csv(corr_r, "corr_r.csv", row.names = TRUE) | |
write.csv(corr_p, "corr_p.csv", row.names = TRUE) |