Re: [R] Random-walk Metropolis-Hasting

2011-11-11 Thread Uwe Ligges
On 11.11.2011 18:48, Gyanendra Pokharel wrote: Following is my code, can some one help on the error at the bottom? mh<-function(iterations,alpha,beta){ + data<-read.table("epidemic.txt",header = TRUE) + attach(data, warn.conflicts = F) + k<-97 + d<- (sqrt((x-x[k])^2 + (y-y[k])^2)) +

[R] Random-walk Metropolis-Hasting

2011-11-11 Thread Gyanendra Pokharel
Following is my code, can some one help on the error at the bottom? > mh<-function(iterations,alpha,beta){ + data<-read.table("epidemic.txt",header = TRUE) + attach(data, warn.conflicts = F) + k<-97 + d <- (sqrt((x-x[k])^2 + (y-y[k])^2)) + p <- 1-exp(-alpha*d^(-beta)) + p.alpha<-1

Re: [R] Random walk

2010-05-12 Thread Giovanni Petris
Oops, I forgot the 'cumsum' stuff. Here it is again, hopefully working this time. > require(MASS) > fz <- function(n, t, rho){ + f <- array(dim = c(t, 2, n)) + V <- matrix(c(1, rho, rho, 1), ncol = 2) + for(i in 1 : n){ + f[,, i] <- apply(mvrnorm(n = t, mu = c(0,0), Sigma = V

Re: [R] Random walk

2010-05-11 Thread Sergio Andrés Estay Cabrera
Dear Giovanni, Thanks so much for your answer, but your script returns gaussian white noise not a random walk, at least the time series generated don't have the expected periodogram for a random walk. That's the reason why I use cumsum, the sum of a white noise is a easy way produce a random

Re: [R] Random walk

2010-05-11 Thread Giovanni Petris
Hi Sergio, Your function does not estimate what you want. In fact it does not estimate anything useful. A random walk is not stationary; in particular, the variance at time t is t. Therefore, estimating variances based on one run, averaging over time, does not make any sense. This is what you are

Re: [R] Random walk

2010-05-10 Thread David Winsemius
On May 10, 2010, at 2:55 PM, Sergio Andrés Estay Cabrera wrote: Dear R users and specially Albyn and Giovanni, thanks for your answers, but in fact I supposed the same at the beginning of my problem. However, when I generate the data seldom I obtain the expected correlation. For example us

Re: [R] Random walk

2010-05-10 Thread Sergio Andrés Estay Cabrera
Dear R users and specially Albyn and Giovanni, thanks for your answers, but in fact I supposed the same at the beginning of my problem. However, when I generate the data seldom I obtain the expected correlation. For example using this code: fz<-function(n,t,rho){ f<-NULL for(i in 1:n){ s<-rmv

Re: [R] Random walk

2010-05-10 Thread Albyn Jones
Sums of correlated increments have the same correlation as the original variables... library(mvtnorm) X<- matrix(0,nrow=1000,ncol=2) for(i in 1:1000){ Y <- rmvnorm(1000,mean=mu,sigma=S) X[i,] <- apply(Y,2,sum) } cor(Y) [,1] [,2] [1,] 1.000 0.4909281 [2,] 0.4909281 1.0

[R] Random walk

2010-05-09 Thread Sergio Andrés Estay Cabrera
Hi everybody, I am trying to generate two random walks with an specific correlation, for example, two random walks of 200 time steps with a correlation 0.7. I built the random walks with: x<-cumsum(rnorm(200, mean=0,sd=1)) y<-cumsum(rnorm(200, mean=0,sd=1)) but I don't know how to fix the c

Re: [R] random walk w/ reflecting boundary: avoid control construct?

2007-10-26 Thread Johannes Hüsing
This is beautiful, thank you! Greetings Johannes __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contai

Re: [R] random walk w/ reflecting boundary: avoid control construct? [SEC=UNCLASSIFIED]

2007-10-24 Thread Crombie, Joe
'l') > lines(walls, col = 'red') > > # shift the walk to be centred around 0. **The walk doesn't start at > zero any more** walls <- walls - wid/2 > -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Charles C.

Re: [R] random walk w/ reflecting boundary: avoid control construct?

2007-10-24 Thread Charles C. Berry
On Wed, 24 Oct 2007, Johannes H?sing wrote: Dear expeRts, recently I asked for a nice way to re-program a problem without using control constructs such as "for" or "sapply(1:length(x), ...". Is there a way to program a random walk with a reflecting boundary without resorting to such constructs?

[R] random walk w/ reflecting boundary: avoid control construct?

2007-10-24 Thread Johannes Hüsing
Dear expeRts, recently I asked for a nice way to re-program a problem without using control constructs such as "for" or "sapply(1:length(x), ...". Is there a way to program a random walk with a reflecting boundary without resorting to such constructs? A working solution is ranwalk <- function(leng