简体   繁体   中英

R matrix correlation p value

We are measuring the groundwater-level at five different spots in an area.

Null hypothesis : the trend/progression of the groundwater-level of each spot is NOT different

Alternative hypothese : the trend/progression of the groundwater-level of each spot is different

We want to proove this statistically.

Below you can see part of the measurement data:

 > head(mydf)
      x1    x2   x3   x4   x5
1    -160  -76  -66  -29  -95
2    -159  -66  -63  -20  -85
3    -153  -63  -55  -19  -81
4    -156  -76  -54  -27  -83
5    -155  -75  -53  -30  -81
6    -145  -64  -49  -20  -71

Here is a chart of the measurement data .

We did correlate the data:

> cor(mydf)
    x1         x2         x3         x4         x5
x1  1.0000000  0.8033349  0.8569253  0.8262110  0.8523034
x2  0.8033349  1.0000000  0.8228611  0.9036943  0.8965484
x3  0.8569253  0.8228611  1.0000000  0.8486466  0.9091440
x4  0.8262110  0.9036943  0.8486466  1.0000000  0.8828055
x5  0.8523034  0.8965484  0.9091440  0.8828055  1.0000000

We also tried to calculate the p-values using rcorr(as.matrix(mydf)) , but received only a matrix of zeros.

We have several questions:

  1. Why is the p value zero and how can we fix that?
  2. Is our way of solving the problem wrong?
  3. How can we extrapolate the given measurement data (see chart) in R?

Guide for you to look at:

http://www.sthda.com/english/wiki/correlation-matrix-a-quick-start-guide-to-analyze-format-and-visualize-a-correlation-matrix-using-r-software

For interpretation of results and how to use, Cross Validated is a better place to post.

With regards to your R questions:

The rcorr() function from the Hmisc package is pretty easy to use.

Example Data:

require(Hmisc)

set.seed(1)
x1 = rnorm(10,seed)
x2 = rnorm(10,seed)
x3 = x2 + rnorm(10,sd=.1,seed)
mydf <- data.frame(x1,x2,x3)
rcorr(as.matrix(mydf))

Gives an output of the Correlation Matrix as well as a pvalue matrix. The guide above can help you flatten it and manipulate it for your needs.

      x1    x2    x3
x1  1.00 -0.38 -0.42
x2 -0.38  1.00  1.00
x3 -0.42  1.00  1.00

n= 10 


P
   x1     x2     x3    
x1        0.2833 0.2304
x2 0.2833        0.0000
x3 0.2304 0.0000 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM