Pearson Correlation

I am trying to run a Pearson correlation on some battery capacity data as shown in this table.

The code I am using is shown in the grab here (I don't seem to have much luck when inserting code directly):

I don't understand the error which seems to suggest that I am missing an argument.

The NULL hypothesis is that there is no correlation between the Predicted Capacity and the Measured Capacity and the Alternative hypothesis is that there is a relationship. Also, I am not fully sure that the "alternative' is 'Less' rather than 'Greater'.

Have I got my R code correct?

Thanks

Julian

Hi @Kerrowman

just type your code into the following format

```
put code in here
```

You have to delete the pipe %>%. So your code has to be

CapacityPb # see how i don't use the pipe operator here
cor.test( rest of your code )

what happened is that your pipe is using the CapacityPb data frame and injecting it into corr.test which lead to the error message.

1 Like

Thanks. I was under the impression that the pipe operator is normally required to use a dataset.

Is there any need to run a t-test on the data as well to further support the Pearson correlation?

The pipe operator is known as "syntactic sugar" in that it's never required for use. When you are using it, it's a way of saying "this R object on the left hand side should be passed to the function on the right hand side". It's a way to avoid assigning intermediate results to a named R object, or generally a way for people to organize their code as a pipeline of operations.

In your next bit of code, you explicitly pass the data you want to use in via the CapacityPb$PredCap, CapacityPB$MeasCap... arguments. So cor.test already has all the information it needs to run; getting the extra reference to CapacityPB via the pipe operator is basically saying "What do you want me to do with that extra information?" and throws an error.

Best,
Randy

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.