-2

I've run a Gibbs sampler and obtained a sample for $X_1$ and $X_2$. I'm trying to recreate a plot like this one:

enter image description here

How do I recreate the walk part on R?

  • 2
    Welcome to SO, Tom! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages) and sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically after `set.seed(1)`). Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jan 25 '21 at 15:43

1 Answers1

0

The most straightforward way I can think of to recreate the walk part would be like this:

x = c(0)

for(i in 2:100){
    x[i] = x[i-1] + floor(runif(1, -5, 5))
}

pdf(file = "My Plot.pdf", width = 4, height = 4)

plot(x, type="l")

dev.off()

Obs.: I made up a simple walk

The result was this one:

enter image description here

rodrigocfaria
  • 440
  • 4
  • 11