[R] Sample Poisson Distribution
Abhijit Dasgupta
Abhijit.Dasgupta at mail.jci.tju.edu
Wed Feb 7 19:10:16 CET 2007
Do you mean that you have 100 samples, each of size 1000. If this is so,
you can perhaps do:
N = 1000
n = 100
x = matrix(rpois(N*n, 3.1), ncol=100) # Generate the appropriate no. of
Poisson samples and rearrange into 100 columns of 1000
output = cbind(means=apply(x,2,mean), vars=apply(x,2,var)) #
apply(x,2,mean) runs "mean" on each column of x
What do you want to draw the histograms of? Histograms of the means
and/or variances can be done by
hist(output$means)
hist(output$vars)
Hope this helps
Abhijit
Thor wrote:
> Hi,
> I'm completely new to R, I am all at sea with the interface and the
> confusing help files, so would appreciate some help to do a simple task.
>
> Need to present the mean and variance of 100 different samples of poisson
> distributions (N=1000, with fixed lambda) in a file in two columnns, and
> then produce histograms.
>
> So far I have figured out:
>
>
>> N <- 1000
>> x <- rpois(N, 3.1) ,
>>
>
> and
>
>> var(x)
>>
> and
>
>> mean(x)
>>
> , and I've seen the hist command, just need to tie it all together. I read
> that loops aren't really used in R, so what do i need to do?
>
> thanks
>
More information about the R-help
mailing list