I have created the following function in R:
timeseriesmodel <- function(N, x0, delta, variance) {
z<-cumsum(rnorm(n=N, mean=0, sd=sqrt(variance)))
t<-1:N
x<-x0+t*delta+z
return(x)}
This function returns a vector 'x' of length 'N', representing the data points of a random walk with drift.
In my case:
timeseriesmodel(250,1,0,1.2)
Now I should repeat this function 100 times, ending up with 100 timeseries data sets of length 250. Then I have to estimate the correlation between the 249th and 250th value of the dataset 'x', using the 100 sets.
As an inexperienced user of R, I don't see how to manipulate the data effectively and calculate/estimate the correlation of the requested data points. Help is very much appreciated.