2
lambda <- runif(10,min=0,max=3)
mean(lambda)
for (i in 1:10){
   N <- rpois(i,mean(lambda))
   mean(N)
   plot(i,mean(N))
}

Hi all, this is a really simple R code block I have here. I am basically trying to create a plot where I can see how the mean of the poisson distribution is changing as I increase its iteration using the rpois function. I would like to post these values (mean(N)) all on the same graph so I can see the change but I am not quite sure how to do that.

I have been googling a lot and I came across qqplot or so but I just started using R few days ago and I have having a lot of trouble.

Any insights would be helpful

1 Answer 1

1

You can use the points function once a plot has been called:

lambda <- runif(10,min=0,max=3)
mean(lambda)

## First plot
N <- rpois(1,mean(lambda))
plot(1,mean(N), xlim = c(1,10))

## Subsequent points
for (i in 2:10){
   N <- rpois(i,mean(lambda))
   points(i,mean(N))
}
Sign up to request clarification or add additional context in comments.

1 Comment

points will plot a single point. lines... a line. See their respective documentation for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.