RGetCCF()
Calculates the cross-correlation of an array of values.
Synopsis
float RGetCCF( const dyn_float& vals1, const dyn_float& vals2, int& optLag = _int_default, int maxLag =0, int userData = 0 );
Parameters
Parameter | Description |
---|---|
vals1 | First array of values. |
vals2 | Second array of values. |
optLag | Return parameter for optimal Lag value. The value is only returned if the parameter maxLag was set to a value other than 0. The optLag time is returned in seconds. |
maxLag | Maximum lag value. The maximumLag value is specified in seconds. |
userData | User data of the function call. The user data variable can be set to an integer value and be used to detect errors when calling R functions. Set the variable to an integer value and when the function is called and an error occurs, the specified integer value is returned. |
Description
Calculates the cross-correlation of an array of values.
Return Value
Correlation result
Example
Calculates the auto-correlation and also returns the optimum lag value. The lag value specifies the maximum time (delay) between all values of different data points. Several values are often needed to calculate a correlation. The lag value specifies the maximum time that is allowed between all values of different data points. In other words between the two values when two data points are compared.
#uses "CtrlR"
main()
{
dyn_float df1 = makeDynFloat(31,31,33,32,34,33,32,35,29,34,38,40,37,38,36,36,36,39,38,40,35,32,34,32,34,29,29,28,31,28,30,34,33,28,31,32,33,33,33,35,36,36,40,38,40,37,40,38,40,38);
dyn_float df2 = makeDynFloat(401,381,382,392,406,372,361,405,392,399,350,342,346,354,304,345,320,317,356,323,386,406,405,396,400,401,365,400,391,398,362,368,363,373,389,370,406,386,402,367,379,380,406,389,374,379,399,406,377,407);
float f;
int optLag; /* returns the optimal lag value between two values when two values are compared */
int maxLag = 2;
f = RGetCCF(df1,df2, optLag,maxLag);
DebugTN("Optimal Lag value:", optLag, "Cross-correlation:", f);
}
Assignment
Availability
See also