| To: | "S-News List" <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | Problem with sample() |
| From: | John Fennick <jhf2@adelphia.net> |
| Date: | Sun, 20 Nov 2005 20:21:14 -0500 |
|
Many thanks to all who responded. No, I was not setting replace = T john Hello Group (I also sent this to S-Plus support, but I wonder is this an oldie or has anyone else experienced it) Using S version 7.2 under Win 2000. I am assuming that sample() and rsample() select a ?truly? random sample from the given population. If this is not true, then my question is mute. It is this: If I generate a binomial sequence using sample() or rsample(), and compare the sample variance with the theoretical, or with sequences generated using rbinom() or runif(), I have an incorrect result. The latter two are consistent and agree with theory, binomial variance = Npq. The means of all three methods used for the sequences agree and are correct, Np. Is there a problem with sample() or what am I missing? Thanks, john EXAMPLE > dim(tt) [1] 2048 100
> length(zz) [1] 2048 > var(zz) [1] 4.420762 > > xx <- (rbinom(2048,30,0.3)) > var(xx) [1] 6.310369 > > > var(yy) [1] 6.322804 > > var(zz) [1] 4.420762 > var(xx) [1] 6.310369 > var(yy) [1] 6.322804 # Npq = 30 * 0.3 * 0.7 = 0.63 These results repeat using rsample() instead of sample() for zz and for samples up to several thousand. jhf2@adelphia.net alt: j.fennick@ieee.org Tel: 603.526.4023 134 Brookside Drive New London, NH 03257 USA |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Sixth SIAM Data Mining Conference - Workshops and Tutorials Announcement, Ian Davidson |
|---|---|
| Next by Date: | Removing 0's, Bert Jacobs |
| Previous by Thread: | Problem with sample(), John Fennick |
| Next by Thread: | Sixth SIAM Data Mining Conference - Workshops and Tutorials Announcement, Ian Davidson |
| Indexes: | [Date] [Thread] [Top] [All Lists] |