COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Mathematica function to calculate correlation coefficient?

• Follow

```Hi everyone,

I solved a differential equation, and got a solution n(t).  Now I have
collected 8 data points at 8 different times.  I plotted the solution of
n(t), and the curve intersect the 8 data points quite well on a graph of
n(t) vs. t.  How do I use Mathematica 7.0 to calculate the correlation
coefficient R^2 value of how well the n(t) solution fit the data points?
Thank you very much.

```
 0

```Surprisingly, you can use the function Correlation to calculate the
correlation between two lists. In your case you should probably use
the set of predicted values and the sat of actual data values.

Cheers -- Sjoerd

On Mar 7, 11:05 am, Yun Zhao <yun.m.z...@gmail.com> wrote:
> Hi everyone,
>
>   I solved a differential equation, and got a solution n(t).  Now I have
> collected 8 data points at 8 different times.  I plotted the solution of
> n(t), and the curve intersect the 8 data points quite well on a graph of
> n(t) vs. t.  How do I use Mathematica 7.0 to calculate the correlation
> coefficient R^2 value of how well the n(t) solution fit the data points?
> Thank you very much.

```
 0

```Thanks for your reply.  But remember, the set of data values is 20 data
points, and my computed distribution of n(t) is a function of t, so
thousands and thousands of points.  When I tried to use

Correlation[data1, n(t)]

I get the error "Correlation::vctmat: The arguments to Correlation are not a
pair of vectors or a pair of matrices of equal length."  Please tell me what
I did wrong.  Thank you.

Correlation::vctmat: "

StyleBox[\"\"\", \"MT\"] The arguments to Correlation are not a pair of
vectors or a pair of matrices of equal length

On Mon, Mar 8, 2010 at 5:13 AM, Sjoerd C. de Vries <
sjoerd.c.devries@gmail.com> wrote:

>  Surprisingly, you can use the function Correlation to calculate the
> correlation between two lists. In your case you should probably use
> the set of predicted values and the sat of actual data values.
>
> Cheers -- Sjoerd
>
> On Mar 7, 11:05 am, Yun Zhao <yun.m.z...@gmail.com> wrote:
> > Hi everyone,
> >
> >   I solved a differential equation, and got a solution n(t).  Now I have
> > collected 8 data points at 8 different times.  I plotted the solution of
> > n(t), and the curve intersect the 8 data points quite well on a graph of
> > n(t) vs. t.  How do I use Mathematica 7.0 to calculate the correlation
> > coefficient R^2 value of how well the n(t) solution fit the data points?
> > Thank you very much.
>
>
>

```
 0

```If n is a InterpolationFunction returned by NDSolve or a symbolic function
returned by Solve, n[t] is obviously not a list of 8 values; it's one
value for each t.

You can create such a list, of course, with, for instance, Array[n,8] or
n/@{.1,.3,.4,.8,.9,1.2,...} (any list of eight t values).

Once you have a pair of same-length lists, Correlation will calculate what
the name says.

Bobby

On Tue, 09 Mar 2010 05:20:19 -0600, Yun Zhao <yun.m.zhao@gmail.com> wrote:

> Thanks for your reply.  But remember, the set of data values is 20 data
> points, and my computed distribution of n(t) is a function of t, so
> thousands and thousands of points.  When I tried to use
>
> Correlation[data1, n(t)]
>
> I get the error "Correlation::vctmat: The arguments to Correlation are
> not a
> pair of vectors or a pair of matrices of equal length."  Please tell me
> what
> I did wrong.  Thank you.
>
> Correlation::vctmat: "
>
> StyleBox[\"\"\", \"MT\"] The arguments to Correlation are not a pair of
> vectors or a pair of matrices of equal length
>
>
> On Mon, Mar 8, 2010 at 5:13 AM, Sjoerd C. de Vries <
> sjoerd.c.devries@gmail.com> wrote:
>
>>  Surprisingly, you can use the function Correlation to calculate the
>> correlation between two lists. In your case you should probably use
>> the set of predicted values and the sat of actual data values.
>>
>> Cheers -- Sjoerd
>>
>> On Mar 7, 11:05 am, Yun Zhao <yun.m.z...@gmail.com> wrote:
>> > Hi everyone,
>> >
>> >   I solved a differential equation, and got a solution n(t).  Now I
>> have
>> > collected 8 data points at 8 different times.  I plotted the solution
>> of
>> > n(t), and the curve intersect the 8 data points quite well on a graph
>> of
>> > n(t) vs. t.  How do I use Mathematica 7.0 to calculate the correlation
>> > coefficient R^2 value of how well the n(t) solution fit the data
>> points?
>> > Thank you very much.
>>
>>
>>
>
>

--
DrMajorBob@yahoo.com

```
 0

```Would Correlation[ ] still work if n(t) and the actual data points were not
linear functions of time?  By that, I mean, n(t) is something like
C1*exp(rate*t)+C2.  I am asking because in one case, where I think I have
some errors in my data, n(t) does not come close to any of the data points,
it is far apart, and Correlations [ ] gives me 0.97.

On Tue, Mar 9, 2010 at 12:27 PM, DrMajorBob <btreat1@austin.rr.com> wrote:

> If n is a InterpolationFunction returned by NDSolve or a symbolic function
> returned by Solve, n[t] is obviously not a list of 8 values; it's one value
> for each t.
>
> You can create such a list, of course, with, for instance, Array[n,8] or
> n/@{.1,.3,.4,.8,.9,1.2,...} (any list of eight t values).
>
> Once you have a pair of same-length lists, Correlation will calculate what
> the name says.
>
> Bobby
>
>
> On Tue, 09 Mar 2010 05:20:19 -0600, Yun Zhao <yun.m.zhao@gmail.com> wrote:
>
> Thanks for your reply.  But remember, the set of data values is 20 data
>> points, and my computed distribution of n(t) is a function of t, so
>> thousands and thousands of points.  When I tried to use
>>
>> Correlation[data1, n(t)]
>>
>> I get the error "Correlation::vctmat: The arguments to Correlation are not
>> a
>> pair of vectors or a pair of matrices of equal length."  Please tell me
>> what
>> I did wrong.  Thank you.
>>
>> Correlation::vctmat: "
>>
>> StyleBox[\"\"\", \"MT\"] The arguments to Correlation are not a pair of
>> vectors or a pair of matrices of equal length
>>
>>
>> On Mon, Mar 8, 2010 at 5:13 AM, Sjoerd C. de Vries <
>> sjoerd.c.devries@gmail.com> wrote:
>>
>>  Surprisingly, you can use the function Correlation to calculate the
>>> correlation between two lists. In your case you should probably use
>>> the set of predicted values and the sat of actual data values.
>>>
>>> Cheers -- Sjoerd
>>>
>>> On Mar 7, 11:05 am, Yun Zhao <yun.m.z...@gmail.com> wrote:
>>> > Hi everyone,
>>> >
>>> >   I solved a differential equation, and got a solution n(t).  Now I
>>> have
>>> > collected 8 data points at 8 different times.  I plotted the solution
>>> of
>>> > n(t), and the curve intersect the 8 data points quite well on a graph
>>> of
>>> > n(t) vs. t.  How do I use Mathematica 7.0 to calculate the correlation
>>> > coefficient R^2 value of how well the n(t) solution fit the data
>>> points?
>>> > Thank you very much.
>>>
>>>
>>>
>>>
>>
>>
>
> --
> DrMajorBob@yahoo.com
>

```
 0

```The data doesn't have to be "close" to have a high correlation; it has to
be "nearly parallel".

t and 10^7+t are perfectly correlated, for instance.

Bobby

On Tue, 09 Mar 2010 12:41:34 -0600, Yun Zhao <yun.m.zhao@gmail.com> wrote:

> Would Correlation[ ] still work if n(t) and the actual data points were
> not
> linear functions of time?  By that, I mean, n(t) is something like
> C1*exp(rate*t)+C2.  I am asking because in one case, where I think I have
> some errors in my data, n(t) does not come close to any of the data
> points,
> it is far apart, and Correlations [ ] gives me 0.97.
>
> On Tue, Mar 9, 2010 at 12:27 PM, DrMajorBob <btreat1@austin.rr.com>
> wrote:
>
>> If n is a InterpolationFunction returned by NDSolve or a symbolic
>> function
>> returned by Solve, n[t] is obviously not a list of 8 values; it's one
>> value
>> for each t.
>>
>> You can create such a list, of course, with, for instance, Array[n,8] or
>> n/@{.1,.3,.4,.8,.9,1.2,...} (any list of eight t values).
>>
>> Once you have a pair of same-length lists, Correlation will calculate
>> what
>> the name says.
>>
>> Bobby
>>
>>
>> On Tue, 09 Mar 2010 05:20:19 -0600, Yun Zhao <yun.m.zhao@gmail.com>
>> wrote:
>>
>> Thanks for your reply.  But remember, the set of data values is 20 data
>>> points, and my computed distribution of n(t) is a function of t, so
>>> thousands and thousands of points.  When I tried to use
>>>
>>> Correlation[data1, n(t)]
>>>
>>> I get the error "Correlation::vctmat: The arguments to Correlation are
>>> not
>>> a
>>> pair of vectors or a pair of matrices of equal length."  Please tell me
>>> what
>>> I did wrong.  Thank you.
>>>
>>> Correlation::vctmat: "
>>>
>>> StyleBox[\"\"\", \"MT\"] The arguments to Correlation are not a pair of
>>> vectors or a pair of matrices of equal length
>>>
>>>
>>> On Mon, Mar 8, 2010 at 5:13 AM, Sjoerd C. de Vries <
>>> sjoerd.c.devries@gmail.com> wrote:
>>>
>>>  Surprisingly, you can use the function Correlation to calculate the
>>>> correlation between two lists. In your case you should probably use
>>>> the set of predicted values and the sat of actual data values.
>>>>
>>>> Cheers -- Sjoerd
>>>>
>>>> On Mar 7, 11:05 am, Yun Zhao <yun.m.z...@gmail.com> wrote:
>>>> > Hi everyone,
>>>> >
>>>> >   I solved a differential equation, and got a solution n(t).  Now I
>>>> have
>>>> > collected 8 data points at 8 different times.  I plotted the
>>>> solution
>>>> of
>>>> > n(t), and the curve intersect the 8 data points quite well on a
>>>> graph
>>>> of
>>>> > n(t) vs. t.  How do I use Mathematica 7.0 to calculate the
>>>> correlation
>>>> > coefficient R^2 value of how well the n(t) solution fit the data
>>>> points?
>>>> > Thank you very much.
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>> DrMajorBob@yahoo.com
>>

--
DrMajorBob@yahoo.com

```
 0

5 Replies
571 Views

Similiar Articles:

7/20/2012 7:30:28 PM