Friday, 15 February 2013

Multiple independent correlations (Pearson) with R -



Multiple independent correlations (Pearson) with R -

i have table columns represent climatic variables, , rows representing info points each of variable. want set simple pearson correlation between every pairwise combination. can manually, nice have function can of these automatically , print results new r object.

county temp gdd ai precip jackson robinson paris rose wine

cor can handle matrices , homecoming matrix. if data.frame df, can run:

df <- data.frame(temp = rnorm(10), gdd=rnorm(10), ai=rnorm(10), precip=rnorm(10)) cor(as.matrix(df)) temp gdd ai precip temp 1.0000000 -0.5946187 -0.4635090 0.8016484 gdd -0.5946187 1.0000000 0.2184197 -0.2878479 ai -0.4635090 0.2184197 1.0000000 -0.2788024 precip 0.8016484 -0.2878479 -0.2788024 1.0000000

if data.frame contains numeric columns, can cor(df). if there's character or factor columns, you'll want run cor on selection of numeric columns df. (now think of it, "asmatrix(df)" part kind of unnecessary).

r correlation

No comments:

Post a Comment