[R] Warning - Naive Question Alert
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Sat Aug 26 21:56:49 CEST 2000
On 26 Aug 2000, Peter Dalgaard BSA wrote:
> "Marc R. Feldesman" <feldesmanm at pdx.edu> writes:
>
> > With that as background and assuming that the data really are normal, is
> > there any way in R (or any of the S engines) to generate a data set that
> > mimics exactly the summary properties reported in a published paper? I
> > know I can use rnorm() and mvrnorm() for this, but neither function will
> > necessarily or very likely return a sample that has the *same* properties
> > as the given population. At best, I can sift though replicates until I
> > find the one closest to the "original". This approach doesn't seem very
> > efficient or valid. Is there another way to do this?
>
> I've been using the following for a case where data were given in the
> form of means and sd:
>
> fake.trypsin<-local({
> xrnorm<-function(n,xbar,s){
> t<-rnorm(n);t<-(t-mean(t))/sd(t);xbar+s*t}
> g.1<-xrnorm(32,128,50.9)
> g.2<-xrnorm(137,152,58.5)
> g.3<-xrnorm(38,194,49.3)
> g.4<-xrnorm(44,207,66.3)
> g.5<-xrnorm(16,215,60)
> g.6<-xrnorm(4,218,14)
> trypsin<-c(g.1,g.2,g.3,g.4,g.5,g.6)
> grp<-rep(1:6,c(32,137,38,44,16,4))
> grpf<-factor(grp)
> data.frame(trypsin,grp,grpf)})
>
> The xrnorm function would seem to be something like what you're
> getting at?
I think Marc wants the multivariate equivalent, and that's just a little
trickier. What I would do it to alter mvrnorm, which contains
matrix(rnorm(p * n), p)
What you want there is a matrix of exactly zero mean (so subtract the mean)
and identity empirical var (so the usual trick is to sphere the data
by taking principal components and re-scaling those).
(Marc: is that enough for you? If not I will try to write and test some
code.)
Brian
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list