[R] Generic code for simulating from a distribution.
matgopa1 at umbc.edu
matgopa1 at umbc.edu
Mon Apr 10 06:05:22 CEST 2006
Hello all,
I have the code below to simulate samples of certain size from a
particular distribution (here,beta distribution) and compute some
statistics for the samples.
betasim2<-function(nsim,n,alpha,beta)
{
sim<-matrix(rbeta(nsim*n,alpha,beta),ncol=n)
xmean<-apply(sim,1,mean)
xvar<-apply(sim,1,var)
xmedian<-apply(sim,1,median)
simset<-data.frame(sampleno=seq1:nsim),means=xmean,vars=xvar,medians=xmedian)
return(simset)
}
I can write a similar coding for any distribution individually.
Now, I would like to have a generic code, say if I specify the
distribution with the parameters and simulation and sample size I would
like to have the simulations done for the mentioned distribution and the
statistics performed.
I would appreciate any help in doing so?
Thanks for your time.
Mathangi
Mathangi Gopalakrishnan
Graduate student
Dept of Mathematics and Statistics
University of Maryland, Baltimore County
Baltimore, MD
More information about the R-help
mailing list