Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-09 Thread Paulo van Breugel
Great, thanks


On Fri, Nov 9, 2012 at 12:28 PM, Glynn Clements wrote:

>
> Markus Metz wrote:
>
> > >> Just wondering, if it is implemented in r.regression.series, would it
> be
> > >> very difficult to port to r.series? Or do the two things function
> different
> > >> internally?
> > >
> > > It could probably be added to r.series quite quickly if someone was
> > > willing to provide definitions for "t-value" and "p-value".
> >
> > The t-value of a simple linear regression can be calculate with
> >
> > t = sqrt(Rsq) * sqrt((n - 2) / (1 - Rsq));
> >
> > Rsq = R squared or coefficient of determination (r.series
> method=detcoeff)
> > n = sample size
>
> In which case, it can be calculated with e.g.
>
> r.series ... output=tmp.rsq,tmp.n method=detcoeff,count
> r.mapcalc 'outmap = sqrt(tmp.rsq * (tmp.n - 2) / (1 - tmp.rsq))'
>
> I've added method=tvalue in r53742.
>
> --
> Glynn Clements 
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-09 Thread 王德辉
Thank you Paulo! I think your way is feasible. For r.series, t could be 
caluclate via R2 using r.mapcalc. I am also  a newcomer to time series 
analysis. Hope r.series may add t,f, p function soon.

Best regard,

Dehui




 

-原始邮件-
发件人: "Paulo van Breugel" 
发送时间: 2012年11月9日 星期五
收件人: "王德辉" 
抄送: "GRASS users email list" 
主题: Re: Re: [GRASS-user] Calculate p value for regression slope in r.series

Hi Dehui,
 
What about my previous suggestion to use dummy variable that indicates time 
periods (fixed values 0, 1,2,3...N) for N time periods? I am new to time series 
analysis, so please let me know if the below makes sense.

So you could use your data (Y) as one time series, and the dummy time variables 
as the second time series (T): Y = bT + c.  Resulting slope, offset and R2 
between r.series and r.regression.series are close to identical. Differences 
are very small (a factor 10¹⁰ smaller then the actual slope or offset value) 
soI assume this is due to some differences in rounding (@MarkusN, do you have 
an idea?)

Concrete, if you have a time series of let's say annual rainfall over 10 years. 
You create 10 layers using r.mapcalc, with all cells of the first layer = 0, 
all cells in the second layer = 1... all cells in the 10th layer = 9. Now you 
have two time series you can use in r.regression.series.

There is the possible problem of auto-correlation, so the t and f values 
calculated with r.regression.series should be considered with care. As said, I 
am new to time series analysis, so will need to study more how to deal with 
this. Not sure that is going to be easy using GRASS.

Cheers,

Paulo





On Thu, Nov 8, 2012 at 2:21 PM, 王德辉  wrote:


r.regression.series is a module to calculate linear regression parameters 
between two time series. I only want to calculate parameters in one time 
series, how to use this model in one time serie condition?

thanks!

dehui


-原始邮件-
发件人: "Paulo van Breugel" 
发送时间: 2012年11月8日 星期四
收件人: "Moritz Lennert" 
抄送: "GRASS users email list" 
主题: Re: [GRASS-user] Calculate p value for regression slope in r.series


Good suggestion, and coincidentally I was just looking at it. Am I correct to 
assume that to mimic the calculation of slope etc in r.series, I would need to 
create a second time series of 'dummy' maps with values 0 for first time 
period, 1 for second time period, etc.? I did this in R and it gave the same 
slope and offset as r.series.

Just wondering, if it is implemented in r.regression.series, would it be very 
difficult to port to r.series? Or do the two things function different 
internally?

Cheers,

Paulo





On Thu, Nov 8, 2012 at 10:55 AM, Moritz Lennert  
wrote:
On 06/11/12 09:55, Paulo van Breugel wrote:
Hi,

I am using r.series to calculate linear regression slope, offset and
coefficient of determination. But any idea how I can get the standard
deviation t-value and p-value of the slope?

Try MarkusN's r.regression.series in the addons for grass7. It allows the 
calculation of t and f values. IIRC, p-value can be calculated from t-value.

Moritz














___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-09 Thread Glynn Clements

Markus Metz wrote:

> >> Just wondering, if it is implemented in r.regression.series, would it be
> >> very difficult to port to r.series? Or do the two things function different
> >> internally?
> >
> > It could probably be added to r.series quite quickly if someone was
> > willing to provide definitions for "t-value" and "p-value".
> 
> The t-value of a simple linear regression can be calculate with
> 
> t = sqrt(Rsq) * sqrt((n - 2) / (1 - Rsq));
> 
> Rsq = R squared or coefficient of determination (r.series method=detcoeff)
> n = sample size

In which case, it can be calculated with e.g.

r.series ... output=tmp.rsq,tmp.n method=detcoeff,count
r.mapcalc 'outmap = sqrt(tmp.rsq * (tmp.n - 2) / (1 - tmp.rsq))'

I've added method=tvalue in r53742.

-- 
Glynn Clements 
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-08 Thread Markus Metz
On Thu, Nov 8, 2012 at 6:22 PM, Glynn Clements  wrote:
>
> Paulo van Breugel wrote:
>
>> Just wondering, if it is implemented in r.regression.series, would it be
>> very difficult to port to r.series? Or do the two things function different
>> internally?
>
> It could probably be added to r.series quite quickly if someone was
> willing to provide definitions for "t-value" and "p-value".

The t-value of a simple linear regression can be calculate with

t = sqrt(Rsq) * sqrt((n - 2) / (1 - Rsq));

Rsq = R squared or coefficient of determination (r.series method=detcoeff)
n = sample size

This formula is used by r.regression.multi and in some modules in
GRASS 5 that also do multiple regressions.

The p-value would then be the cumulative probability of observing t
according to Student's t-distribution for given n. I think somewhere
in GRASS is a function to calculate p for n = inf (normal
distribution). Maybe somewhere hidden there is also a function for
small n?

Markus M
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-08 Thread Glynn Clements

Paulo van Breugel wrote:

> Just wondering, if it is implemented in r.regression.series, would it be
> very difficult to port to r.series? Or do the two things function different
> internally?

It could probably be added to r.series quite quickly if someone was
willing to provide definitions for "t-value" and "p-value".

-- 
Glynn Clements 
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-08 Thread Paulo van Breugel
Hi Dehui,

What about my previous suggestion to use dummy variable that indicates time
periods (fixed values 0, 1,2,3...N) for N time periods? I am new to time
series analysis, so please let me know if the below makes sense.

So you could use your data (Y) as one time series, and the dummy time
variables as the second time series (T): Y = bT + c.  Resulting slope,
offset and R2 between r.series and r.regression.series are close to
identical. Differences are very small (a factor 10¹⁰ smaller then the
actual slope or offset value) so I assume this is due to some differences
in rounding (@MarkusN, do you have an idea?)

Concrete, if you have a time series of let's say annual rainfall over 10
years. You create 10 layers using r.mapcalc, with all cells of the first
layer = 0, all cells in the second layer = 1... all cells in the 10th layer
= 9. Now you have two time series you can use in r.regression.series.

There is the possible problem of auto-correlation, so the t and f values
calculated with r.regression.series should be considered with care. As
said, I am new to time series analysis, so will need to study more how to
deal with this. Not sure that is going to be easy using GRASS.

Cheers,

Paulo



On Thu, Nov 8, 2012 at 2:21 PM, 王德辉  wrote:

> r.regression.series is a module to calculate linear regression parameters
> between two time series. I only want to calculate parameters in one time
> series, how to use this model in one time serie condition?
>
> thanks!
>
> dehui
>
> -原始邮件-
> *发件人:* "Paulo van Breugel" 
> *发送时间:* 2012年11月8日 星期四
> *收件人:* "Moritz Lennert" 
> *抄送:* "GRASS users email list" 
> *主题:* Re: [GRASS-user] Calculate p value for regression slope in r.series
>
>
> Good suggestion, and coincidentally I was just looking at it. Am I correct
> to assume that to mimic the calculation of slope etc in r.series, I would
> need to create a second time series of 'dummy' maps with values 0 for first
> time period, 1 for second time period, etc.? I did this in R and it gave
> the same slope and offset as r.series.
>
> Just wondering, if it is implemented in r.regression.series, would it be
> very difficult to port to r.series? Or do the two things function different
> internally?
>
> Cheers,
>
> Paulo
>
>
>
> On Thu, Nov 8, 2012 at 10:55 AM, Moritz Lennert <
> mlenn...@club.worldonline.be> wrote:
>
>> On 06/11/12 09:55, Paulo van Breugel wrote:
>>
>>> Hi,
>>>
>>> I am using r.series to calculate linear regression slope, offset and
>>> coefficient of determination. But any idea how I can get the standard
>>> deviation t-value and p-value of the slope?
>>>
>>
>> Try MarkusN's r.regression.series in the addons for grass7. It allows the
>> calculation of t and f values. IIRC, p-value can be calculated from t-value.
>>
>> Moritz
>>
>
>
>
>
>
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-08 Thread 王德辉
r.regression.series is a module to calculate linear regression parameters 
between two time series. I only want to calculate parameters in one time 
series, how to use this model in one time serie condition?

thanks!

dehui


-原始邮件-
发件人: "Paulo van Breugel" 
发送时间: 2012年11月8日 星期四
收件人: "Moritz Lennert" 
抄送: "GRASS users email list" 
主题: Re: [GRASS-user] Calculate p value for regression slope in r.series

Good suggestion, and coincidentally I was just looking at it. Am I correct to 
assume that to mimic the calculation of slope etc in r.series, I would need to 
create a second time series of 'dummy' maps with values 0 for first time 
period, 1 for second time period, etc.? I did this in R and it gave the same 
slope and offset as r.series.

Just wondering, if it is implemented in r.regression.series, would it be very 
difficult to port to r.series? Or do the two things function different 
internally?

Cheers,

Paulo





On Thu, Nov 8, 2012 at 10:55 AM, Moritz Lennert  
wrote:
On 06/11/12 09:55, Paulo van Breugel wrote:
Hi,

I am using r.series to calculate linear regression slope, offset and
coefficient of determination. But any idea how I can get the standard
deviation t-value and p-value of the slope?

Try MarkusN's r.regression.series in the addons for grass7. It allows the 
calculation of t and f values. IIRC, p-value can be calculated from t-value.

Moritz







___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-08 Thread Paulo van Breugel
Good suggestion, and coincidentally I was just looking at it. Am I correct
to assume that to mimic the calculation of slope etc in r.series, I would
need to create a second time series of 'dummy' maps with values 0 for first
time period, 1 for second time period, etc.? I did this in R and it gave
the same slope and offset as r.series.

Just wondering, if it is implemented in r.regression.series, would it be
very difficult to port to r.series? Or do the two things function different
internally?

Cheers,

Paulo



On Thu, Nov 8, 2012 at 10:55 AM, Moritz Lennert <
mlenn...@club.worldonline.be> wrote:

> On 06/11/12 09:55, Paulo van Breugel wrote:
>
>> Hi,
>>
>> I am using r.series to calculate linear regression slope, offset and
>> coefficient of determination. But any idea how I can get the standard
>> deviation t-value and p-value of the slope?
>>
>
> Try MarkusN's r.regression.series in the addons for grass7. It allows the
> calculation of t and f values. IIRC, p-value can be calculated from t-value.
>
> Moritz
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-08 Thread Moritz Lennert

On 06/11/12 09:55, Paulo van Breugel wrote:

Hi,

I am using r.series to calculate linear regression slope, offset and
coefficient of determination. But any idea how I can get the standard
deviation t-value and p-value of the slope?


Try MarkusN's r.regression.series in the addons for grass7. It allows 
the calculation of t and f values. IIRC, p-value can be calculated from 
t-value.


Moritz
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-07 Thread 王德辉
This is also my urgent need fuction. waiting ...


> -原始邮件-
> 发件人: "Markus Neteler" 
> 发送时间: 2012年11月7日 星期三
> 收件人: "Paulo van Breugel" 
> 抄送: "GRASS users email list" 
> 主题: Re: [GRASS-user] Calculate p value for regression slope in r.series
> 
> On Tue, Nov 6, 2012 at 9:55 AM, Paulo van Breugel
>  wrote:
> > Hi,
> >
> > I am using r.series to calculate linear regression slope, offset and
> > coefficient of determination. But any idea how I can get the standard
> > deviation t-value and p-value of the slope?
> 
> It is not yet implemented... suggestions where to find an existing
> C implementation which could be "recycled" (i.e. be GPL compliant)
> are welcome.
> 
> Markus
> ___
> grass-user mailing list
> grass-user@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user



___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-07 Thread Paulo van Breugel
I have not clue about C programming, but could there be anything in the Gnu
Scientific Library (GSL - http://www.gnu.org/software/gsl/)? See also this
question on StackOverflow:
http://stackoverflow.com/questions/5503733/getting-p-value-for-linear-regression-in-c-gsl-fit-linear-function-from-gsl-li

Cheers,

Paulo


On Wed, Nov 7, 2012 at 9:53 AM, Paulo van Breugel wrote:

> OK, thanks for the info.
>
>
> On Wed, Nov 7, 2012 at 9:45 AM, Markus Neteler  wrote:
>
>> On Tue, Nov 6, 2012 at 9:55 AM, Paulo van Breugel
>>  wrote:
>> > Hi,
>> >
>> > I am using r.series to calculate linear regression slope, offset and
>> > coefficient of determination. But any idea how I can get the standard
>> > deviation t-value and p-value of the slope?
>>
>> It is not yet implemented... suggestions where to find an existing
>> C implementation which could be "recycled" (i.e. be GPL compliant)
>> are welcome.
>>
>> Markus
>>
>
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-07 Thread Paulo van Breugel
OK, thanks for the info.


On Wed, Nov 7, 2012 at 9:45 AM, Markus Neteler  wrote:

> On Tue, Nov 6, 2012 at 9:55 AM, Paulo van Breugel
>  wrote:
> > Hi,
> >
> > I am using r.series to calculate linear regression slope, offset and
> > coefficient of determination. But any idea how I can get the standard
> > deviation t-value and p-value of the slope?
>
> It is not yet implemented... suggestions where to find an existing
> C implementation which could be "recycled" (i.e. be GPL compliant)
> are welcome.
>
> Markus
>
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Calculate p value for regression slope in r.series

2012-11-07 Thread Markus Neteler
On Tue, Nov 6, 2012 at 9:55 AM, Paulo van Breugel
 wrote:
> Hi,
>
> I am using r.series to calculate linear regression slope, offset and
> coefficient of determination. But any idea how I can get the standard
> deviation t-value and p-value of the slope?

It is not yet implemented... suggestions where to find an existing
C implementation which could be "recycled" (i.e. be GPL compliant)
are welcome.

Markus
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user