Programmer Guide/Command Reference/EVAL/corrfun: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Compute the autocorrelation or cross-correlation function.
Compute the autocorrelation or cross-correlation function.
----
;Usage:  
;Usage:  
:{|class="keinrahmen"
:{|class="keinrahmen"
|'''<code>corrfun(''x''<sub>vector</sub> {, ''n'' {, ''scale''}})</code>'''
|<code>corrfun(''x''<sub>vector</sub> {, ''n'' {, ''scale'' {, cyclic}}})</code>
| ... autocorrelation of ''x''
| ... autocorrelation of ''x''
|-
|-
|'''<code>corrfun(''x''<sub>vector</sub>, ''y''<sub>vector</sub> {, ''n'' {, ''scale''}})</code>'''
|<code>corrfun(''x''<sub>vector</sub>, ''y''<sub>vector</sub> {, ''n'' {, ''scale'' {, cylic}}})</code>
| ... cross correlation of ''x'' and ''y''
| ... cross correlation of ''x'' and ''y''
|}
|}
Line 13: Line 12:
:;''n'': the number of lags; 0 < n < <code>ncol(''x'')</code> (default=<code>ncol(''x'')/2</code>)
:;''n'': the number of lags; 0 < n < <code>ncol(''x'')</code> (default=<code>ncol(''x'')/2</code>)
:;''scale'': specifies the scaling of the function:
:;''scale'': specifies the scaling of the function:
::{|class=keinrahmen"
::{|class="keinrahmen"
|''scale=0'' ||... no scaling (default)
|''scale=0''  
|''scale=1'' ||... "biased", each lag ''i'' is scaled by the length of ''x'' (<code>1/ncol(''x'')</code>)
| ... no scaling (default)
|''scale=2'' ||... "unbiased", each lag ''i'' is scaled by the number of correlated elements (<code>1/(ncol(''x'')-1)</code>)
 
;Result 1: The correlecation coefficient ''r'' (product-moment correlation) of the vectors ''x'' and ''y''.
:<code>''r'' = var(''x'', ''y'') / sqrt( var(''x'') * var(''y'') )</code>
----
;Usage 1: '''<code>var(''x''<sub>vector</sub>, ''y''<sub>vector</sub>)</code>'''
;Result 1: The correlecation coefficient ''r'' (product-moment correlation) of the vectors ''x'' and ''y''.
:<code>''r'' = var(''x'', ''y'') / sqrt( var(''x'') * var(''y'') )</code>
----
;Usage 2: '''<code>var(''x''<sub>matrix</sub>)</code>'''
:'''<code>var(''x''<sub>matrix</sub>, ''y''<sub>scalar</sub>)</code>'''
:'''<code>var(''x''<sub>matrix</sub>, ''y''<sub>vector</sub>)</code>'''
;Result 2: The correlation matrix ''r'' of the column vectors of ''x''.
:<code>''r''[i,j] = var(''x[*,i]'', ''x''[*,j]) / sqrt( var(''x''[*,i]) * var(''x''[*,j]) ) , with: i,j = 0..ncol(''x'')-1</code>
:If the argument ''y'' is supplied, it is used as column average like for the computation of the [[Programmer_Guide/Command_Reference/EVAL/var|covariance matrix]].
 
;See also: [[Programmer_Guide/Command_Reference/EVAL/avr|avr]], [[Programmer_Guide/Command_Reference/EVAL/dev|dev]], [[Programmer_Guide/Command_Reference/EVAL/var|var]], [[Programmer_Guide/Command_Reference/EVAL/corrfun|corrfun]]
 
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]
 
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
=====corrfun=====
 
{|
|-
|-
|corrfun(x, <var>lags</var>, <var>scale</var>)
|''scale=1''
|Calculate the coefficients 0..lags-1 of the auto-correlation function of the vector <var>x</var>.{|
| ... "biased", each lag ''i'' is scaled by the length of ''x'' (<code>1/ncol(''x'')</code>)
|-
|-
|
|''scale=2''
|
| ... "unbiased", each lag ''i'' is scaled by the number of correlated elements (<code>1/(ncol(''x'')-''i'')</code>)
|
|}
|-
:;''cyclic'': normal or cyclic indexing
|lags
::{|class="keinrahmen"
|the number of coefficients
|''cyclic=0''
|def.=nrow(x)/2
| ... normal (default); (<code>acf[i]=sum(x[t]*y[t+i], t=0..ncol(x)-1-i)<code>)
|-
|scale
|the scaling
|def.=0
|-
|
|0=no scaling
|-
|-
|  
|''cyclic!=0'' 
|1=scaling with "1 / nrow(x)",
| ... cyclic; (<code>acf[i]=sum(x[t]*y[(t+i)%ncol(x)], t=0..ncol(x)-1)<code>)
|-
|
|2=scaling with "1 / (nrow(x) <nowiki>-</nowiki> lag)"
|}
|}


The result is a vector with <var>lags</var> elements.
;Result: The autocorrelation function of the data vector ''x'' or the cross correlation function of the vectors ''x'' and ''y''. The result is a scalar (if ''n''=1) or a vector with ''n'' elements.
|-
;See also: [[../corr|corr]]
|corrfun(x, <var>y</var>, <var>lags</var>, <var>scale</var>)
 
|Calculate the coefficients 0..lags-1 of the cross-correlation function of the vectors <var>x</var> and <var>y</var>. The parameters are the same as for the auto-correlation function.
[[../#Functions|<function list>]]
|}

Latest revision as of 09:39, 1 September 2023

Compute the autocorrelation or cross-correlation function.

Usage
corrfun(xvector {, n {, scale {, cyclic}}}) ... autocorrelation of x
corrfun(xvector, yvector {, n {, scale {, cylic}}}) ... cross correlation of x and y
x, y
data vectors
n
the number of lags; 0 < n < ncol(x) (default=ncol(x)/2)
scale
specifies the scaling of the function:
scale=0 ... no scaling (default)
scale=1 ... "biased", each lag i is scaled by the length of x (1/ncol(x))
scale=2 ... "unbiased", each lag i is scaled by the number of correlated elements (1/(ncol(x)-i))
cyclic
normal or cyclic indexing
cyclic=0 ... normal (default); (acf[i]=sum(x[t]*y[t+i], t=0..ncol(x)-1-i))
cyclic!=0 ... cyclic; (acf[i]=sum(x[t]*y[(t+i)%ncol(x)], t=0..ncol(x)-1))
Result
The autocorrelation function of the data vector x or the cross correlation function of the vectors x and y. The result is a scalar (if n=1) or a vector with n elements.
See also
corr

<function list>

Navigation menu

Personal tools