[R] plotting the ending point in a for loop

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Jul 27 19:58:12 CEST 2011


Don't really undertsand, are you looking for

points(B2[N], B1[N])

  ?

Uwe Ligges



On 27.07.2011 11:59, Rebecca Gray wrote:
> Hello,
>
> I would appreciate if someone could help me with this query. I would like to
> plot a  line chart of all of the points in a "for" loop. I would also like
> to plot the final point with a symbol (to show where the random walk ends).
> Here is the code I am using:
>
> Brownian.fn<- function(mu, sigma, T, N){
>
> dt<- T/N
>
> t<- c(rep(NA, N))
> B1<- c(rep(NA, N))
> B2<- c(rep(NA, N))
>
> t[1]<- 0
> B1[1]<- 0
> B2[1]<- 0
>
>
> for(j in 2:N){
>
>      t[j]<- t[j-1] + dt
>      B1[j]<- B1[j-1] + mu*dt + sigma*sqrt(dt)*rnorm(1, mean = 0, sd = 1)
>
>      B2[j]<- B2[j-1] + mu*dt + sigma*sqrt(dt)*rnorm(1, mean = 0, sd = 1)
>
> }
>
>
> plot(y = B2, x = B1, xlim = c(-2, 2),
>      ylim = c(-2, 2), type ="l", lty = 1, col=10)
>
> }
>
> Thank you for your help.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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-contained, reproducible code.



More information about the R-help mailing list