Hi, I am hoping someone can help me with a sampling question. I am using the following function to sample 10 unique observations: x <- sample(1:100, 10, replace=F) Given the first 10 observations, I need to sample another 5 unique observations from the remainder. I essentially want to do a Monte Carlo type analysis on the results. I would appreciate any feedback. Thanks -- View this message in context: http://n4.nabble.com/Conditional-Sampling-tp1012072p1012072.html Sent from the R help mailing list archive at Nabble.com.
On 12-Jan-10 12:58:13, ehcpieterse wrote:> Hi, > > I am hoping someone can help me with a sampling question. > > I am using the following function to sample 10 unique observations: > x <- sample(1:100, 10, replace=F) > Given the first 10 observations, I need to sample another 5 unique > observations from the remainder. I essentially want to do a Monte > Carlo type analysis on the results. > > I would appreciate any feedback. > > Thanks > --If your second sampling is to be on the same footing as the first, i.e. a random subset of 5 out of the remaining 90, then this is equivalent to sampling 15 in the first place and using the first 10 of these as your first sample: set.seed(54321) x0 <- sample(1:100, 15, replace=F) x <- x0[1:10] y <- x0[-(1:10)] x0 # [1] 43 50 18 27 21 83 5 20 32 34 13 61 4 57 86 x # [1] 43 50 18 27 21 83 5 20 32 34 y # [1] 13 61 4 57 86 set.seed(54321) sample(1:100, 10, replace=F) # [1] 43 50 18 27 21 83 5 20 32 34 However, if the manner of taking the second sample from the remainder will depend on the results of the first sample, then further consideration is necessary. If this is the case, can you indicate how the values in the first sample would influence how the second sample is to be obtained? Another approach, which leaves more options, is to use sample.int(): set.seed(54321) X <- (1:100) ## (or any other 100 values) n <- sample.int(100,10,replace=FALSE) ## returns subset of (1:100) x <- X[n] Y <- X[-n] y <- sample(Y,5,replace=FALSE) x # [1] 43 50 18 27 21 83 5 20 32 34 ## (as before) y # [1] 14 70 4 66 96 ## (as before) Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 12-Jan-10 Time: 13:21:21 ------------------------------ XFMail ------------------------------
Thanks Ted, your solution does make perfect sense. The only question I still have is that I would like to sample the remaining 5 observations after I have randomly selected the first 10. Given the initial 10, I would like to sample the following 5 say 1,000 times to get a simulated conditional sample, if that makes any sense. I want to build this into an iterative process to see how the first sample affects the resulting samples. Even though all the observations have the same probabilty to get sampled, they each have a different expected value. -- View this message in context: http://n4.nabble.com/Conditional-Sampling-tp1012072p1012114.html Sent from the R help mailing list archive at Nabble.com.
Would the following work, or is there a reason why it would not? risk.set <- 1:100 first.10 <- sample(risk.set, 10) remainder <- setdiff(risk.set, first.10) for ( i in 1:1000 ) { next.5 <- sample(remainder, 5) do.something.with(next.5) } Best, Magnus On 1/12/2010 9:00 AM, ehcpieterse wrote:> > Thanks Ted, your solution does make perfect sense. > > The only question I still have is that I would like to sample the remaining > 5 observations after I have randomly selected the first 10. Given the > initial 10, I would like to sample the following 5 say 1,000 times to get a > simulated conditional sample, if that makes any sense. > > I want to build this into an iterative process to see how the first sample > affects the resulting samples. Even though all the observations have the > same probabilty to get sampled, they each have a different expected value.
On 12-Jan-10 14:00:24, ehcpieterse wrote:> Thanks Ted, your solution does make perfect sense. > > The only question I still have is that I would like to sample > the remaining 5 observations after I have randomly selected the > first 10. Given the initial 10, I would like to sample the > following 5 say 1,000 times to get a simulated conditional sample, > if that makes any sense. > > I want to build this into an iterative process to see how the > first sample affects the resulting samples. Even though all the > observations have the same probabilty to get sampled, they each > have a different expected value. > --OK, if I now understand you, you are interested in the properties of the remaining (90) observations, given that they do not include any of the (10) cases sampled in the first round. In that case, I think you should adopt the sample.int() approach I also suggested: X <- (1:100) ## (or any other 100 values) n <- sample.int(100,10,replace=FALSE) ## returns subset of (1:100) x <- X[n] Y <- X[-n] ## The set remaining after the first 10 were taken ## Now you can sample repeatedly from Y until your eyes fall out. ## So build up a matrix of (say) 1000 samples from Y: M <- sample(Y,5,replace=FALSE) for(i in (2:1000)){ M <- rbind(M,sample(Y,5,replace=FALSE)) } The repeated samples M of 5 from Y of course imply replacing each sample of 5 back in Y, so they are available at each turn. You can not, of course, sample 1000*5 from 100 without replacement! (Each sample of 5 is obtained without replacement, however). I hope this is getting close! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 12-Jan-10 Time: 14:34:13 ------------------------------ XFMail ------------------------------
The last 2 lines of your code can be replaced with: M <- replicate(1000, sample(Y,5,replace=FALSE) ) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Ted Harding > Sent: Tuesday, January 12, 2010 7:34 AM > To: r-help at r-project.org > Cc: ehcpieterse > Subject: Re: [R] Conditional Sampling > > On 12-Jan-10 14:00:24, ehcpieterse wrote: > > Thanks Ted, your solution does make perfect sense. > > > > The only question I still have is that I would like to sample > > the remaining 5 observations after I have randomly selected the > > first 10. Given the initial 10, I would like to sample the > > following 5 say 1,000 times to get a simulated conditional sample, > > if that makes any sense. > > > > I want to build this into an iterative process to see how the > > first sample affects the resulting samples. Even though all the > > observations have the same probabilty to get sampled, they each > > have a different expected value. > > -- > > OK, if I now understand you, you are interested in the properties > of the remaining (90) observations, given that they do not include > any of the (10) cases sampled in the first round. > > In that case, I think you should adopt the sample.int() approach > I also suggested: > > X <- (1:100) ## (or any other 100 values) > n <- sample.int(100,10,replace=FALSE) ## returns subset of (1:100) > x <- X[n] > Y <- X[-n] ## The set remaining after the first 10 were taken > ## Now you can sample repeatedly from Y until your eyes fall out. > ## So build up a matrix of (say) 1000 samples from Y: > M <- sample(Y,5,replace=FALSE) > for(i in (2:1000)){ M <- rbind(M,sample(Y,5,replace=FALSE)) } > > The repeated samples M of 5 from Y of course imply replacing each > sample of 5 back in Y, so they are available at each turn. You can > not, of course, sample 1000*5 from 100 without replacement! (Each > sample of 5 is obtained without replacement, however). > > I hope this is getting close! > Ted. > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> > Fax-to-email: +44 (0)870 094 0861 > Date: 12-Jan-10 Time: 14:34:13 > ------------------------------ XFMail ------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi there, My question relates to getting information about R packages. In particular i would like to be able to find from within R: what are a packages dependencies what are a packages reverse dependencies does a package contain a dll The reason i ask is: The organisation that i work for is introducing a secure intranet operating on windows PCs and laptops, and this requires that all software / executables / dlls are validated before they are combined to produce a generic PC build. I would like to maximise the packages available to our staff and so for the packages that we have listed as buisness needs, i would like to include all reverse dependencies of this collection that do not have dlls. I hope this makes sense (the question not the reason). Kind regards, Colin. [[alternative HTML version deleted]]
Hi Colin, The pkgDepTools package from Bioconductor will help with question #1: http://bioconductor.org/packages/2.5/bioc/html/pkgDepTools.html I am not positive on this, but I believe this package is also used to determine the reverse dependencies that would be listed on that page if there were any for this package. An example with reverse dependencies is e.g., the IRanges package: http://bioconductor.org/packages/2.5/bioc/html/IRanges.html The maintainer (Seth Falcon) would know for sure if the package will do reverse dependencies as well. Best, Jim Colin Millar wrote:> Hi there, > > My question relates to getting information about R packages. In particular i would like to be able to find from within R: > what are a packages dependencies > what are a packages reverse dependencies > does a package contain a dll > > The reason i ask is: > > The organisation that i work for is introducing a secure intranet operating on windows PCs and laptops, and this requires that all software / executables / dlls are validated before they are combined to produce a generic PC build. > > I would like to maximise the packages available to our staff and so for the packages that we have listed as buisness needs, i would like to include all reverse dependencies of this collection that do not have dlls. > > I hope this makes sense (the question not the reason). > > Kind regards, > Colin. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- James W. MacDonald, M.S. Biostatistician Douglas Lab University of Michigan Department of Human Genetics 5912 Buhl 1241 E. Catherine St. Ann Arbor MI 48109-5618 734-615-7826 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues
See the dep function defined here: http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7159.html On Wed, Jan 13, 2010 at 11:39 AM, Colin Millar <C.Millar at marlab.ac.uk> wrote:> Hi there, > > My question relates to getting information about R packages. ?In particular i would like to be able to find from within R: > ?what are a packages dependencies > ?what are a packages reverse dependencies > ?does a package contain a dll > > The reason i ask is: > > The organisation that i work for is introducing a secure intranet operating on windows PCs and laptops, and this requires that all software / executables / dlls are validated before they are combined to produce a generic PC build. > > I would like to maximise the packages available to our staff and so for the packages that we have listed as buisness needs, i would like to include all reverse dependencies of this collection that do not have dlls. > > I hope this makes sense (the question not the reason). > > Kind regards, > Colin. > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Thanks guys! The tools functions are very useful, and also the the utils:::.clean_up_dependencies hiding in there, which I had a managed to do myself but in far more lines! I think I am going to download each zip file one by one to find if there are dlls - which sounds like an overnight job to me. Many thanks again, Colin. -----Original Message----- From: Uwe Ligges [mailto:ligges at statistik.tu-dortmund.de] Sent: 14 January 2010 14:06 To: Colin Millar Cc: Gabor Grothendieck; r-help at r-project.org Subject: Re: [R] R package dependencies For the original question: > what are a packages dependencies tools:::package.dependencies(available.packages()) > what are a packages reverse dependencies tools:::dependsOnPkgs(available.packages()[,1]) > does a package contain a dll If the package has been installed already and you want to get the number of dlls in libs: length(grep("\\.dll$", dir(system.file(package="foo", "libs")))) or if not installed, you can get an idea by looking at the check logs on CRAN. If they contain a line * checking line endings in C/C++/Fortran sources/headers ... OK they also contain compiled code. This is not a save test, though. Uwe Ligges On 14.01.2010 12:27, Colin Millar wrote:> Thanks Gabor, > > Are you or anyone aware if there is a text list of of packagecontents? The only way i have managed to get information like the number of dlls per package is by downloading the zip file to a tempporary file and listing its contents via unzip(..., list = TRUE). However, downloading every package on CRAN is a time consuming so if there was a more efficient way of finding the contents of each it would be useful to know.> > The code i am using on R2.10.1 on windows 7 > > contriburl<-"http://cran.uk.r-project.org/bin/windows/contrib/2.10<http://cran.uk.r- project.org/bin/windows/contrib/2.10> "> destdir<- "C:/colin/SCOTS-user-group/pkgs" > lab.pkgs<-c("gamair","mgcv","survival","lme4","nlme","lattice","MASS","nnet","spli nes","stats4", "stats", "methods")> > available<- available.packages(contriburl = contriburl) > fnames<- paste(available[,"Repository"], available[,"File"], sep "/") > tmpf<- paste(tempfile(), ".zip", sep = "") > > pkg.contents<- lapply(fnames, function(x) {download.file(x, tmpf);unzip(tmpf, list = TRUE)})> ndlls<- sapply(pkg.contents, function(x) sum( grepl( ".dll", x $ Name)))> pkg.summ<- data.frame(pkg = rownames(available), dll = ndlls) > > > Thanks again, > Colin. > > ________________________________ > > From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] > Sent: Wed 13/01/2010 22:09 > To: Colin Millar > Cc: r-help at r-project.org > Subject: Re: [R] R package dependencies > > > > See the dep function defined here: > http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7159.html > > On Wed, Jan 13, 2010 at 11:39 AM, Colin Millar<C.Millar at marlab.ac.uk>wrote:>> Hi there, >> >> My question relates to getting information about R packages. Inparticular i would like to be able to find from within R:>> what are a packages dependencies >> what are a packages reverse dependencies >> does a package contain a dll >> >> The reason i ask is: >> >> The organisation that i work for is introducing a secure intranetoperating on windows PCs and laptops, and this requires that all software / executables / dlls are validated before they are combined to produce a generic PC build.>> >> I would like to maximise the packages available to our staff and sofor the packages that we have listed as buisness needs, i would like to include all reverse dependencies of this collection that do not have dlls.>> >> I hope this makes sense (the question not the reason). >> >> Kind regards, >> Colin. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html>> and provide commented, minimal, self-contained, reproducible code. >> > > ______________________________________________________________________ > This email has been scanned by the MessageLabs Email Security System. > For more information please visit http://www.messagelabs.com/email > ______________________________________________________________________ > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email
On 1/13/10 11:21 AM, James W. MacDonald wrote:> Hi Colin, > > The pkgDepTools package from Bioconductor will help with question > #1: > > http://bioconductor.org/packages/2.5/bioc/html/pkgDepTools.html > > I am not positive on this, but I believe this package is also used > to determine the reverse dependencies that would be listed on that > page if there were any for this package. An example with reverse > dependencies is e.g., the IRanges package: > > http://bioconductor.org/packages/2.5/bioc/html/IRanges.html > > The maintainer (Seth Falcon) would know for sure if the package will > do reverse dependencies as well.There is an example in the vignette for pkgDepTools that shows how to get reverse dependencies:> The edge directions of the dependency graph can be reversed and the > resulting graph used to determine the set of packages that make use > of (even indirectly) a given package. For example, one might like to > know which packages make use of the methods package. Here is one way > to do that: <example follows in the vignette>+ seth -- Seth Falcon | @sfalcon | http://userprimary.net/user