Dear list As a relative newbie to R I am after some basic help. I am wanting to simulate a data set consisting of a Y variable and several X variables, all either binary or discrete. I am wondering how to go about doing this and have failed to find anything about this in the R -help. Thanks in advance Laura _______________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 9 Aug 2002 laura at bayesian-bay.freeserve.co.uk wrote:> Dear list > > As a relative newbie to R I am after some basic help. > > I am wanting to simulate a data set consisting of a Y variable and several X variables, all either binary or discrete. I am wondering how to go about doing this and have failed to find anything about this in the R -help. > > Thanks in advance > Laura >Laura, have a look at help(rbinom) and help(rpois). -- Uli Flenker Institute of Biochemistry German Sport University Cologne Carl-Diem-Weg 6 50933 Cologne Phone 0049/221/4982-506 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 08/09/02 13:28, laura at bayesian-bay.freeserve.co.uk wrote:>I am wanting to simulate a data set consisting of a Y variableand several X variables, all either binary or discrete. I am wondering how to go about doing this and have failed to find anything about this in the R -help. Try runif() in the base package. It generates random numbers from a uniform distribution. So, for example, if you want a binary variable with an expectation of .75, and 1000 observations, say: runif(1000)<=.75 Or, if you want to see the numbers right away: (runif(1000)<=.75)+0 To generate a factor with several levels, you can apply cut() to runif(). That may be sufficient, but note that factors are "categorical variables." Of course, you assign these to variables, e.g., x1 <- runif(1000)<=.75 and then use these in your model. Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron Questionnaires: http://www.psych.upenn.edu/~baron/qs.html Psychology webmaster: http://www.psych.upenn.edu/ R page: http://finzi.psych.upenn.edu/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._