Re: [R] Inheritance for S3 classes

2017-08-07 Thread Bert Gunter
The S3 class model isn't really a class model. It's more a way of overloading functions. So it's rather simple, and there's less there than you might be expecting. I always thought the "Object Oriented Programming" chapter of the R language definition manual that ships with R was a very good treatm

Re: [R] Nested for loop

2017-08-07 Thread Kirsten Morehouse
Hi Caitlin and Ben, Thanks for your responses! My issue is that I'd like to create one continuous line, rather than 3 lines overlayed. The code I've attached works for a population of 400 and samples 100 times. I'd like to extend this to 300 samples and 3 populations. So, the x-axis would range f

[R] Inheritance for S3 classes

2017-08-07 Thread Kym Nitschke
Hi R Users, I am relatively new to programming in R … so I apologise if my questions appear ‘dumb’. I am using a package that defines a number of S3 classes. I want to create an S3 child class of one of these classes. The parent class has a contractor with many arguments. I have been having di

Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-07 Thread Marine Regis
Thanks for your answer. However, my variable is simulated from the cumulative distribution function of the Poisson distribution. So, the pattern obtained from the function "qpois" is not the same as the observed pattern (i.e., obtained from the function "ppois") set.seed(5) mortality_probabili

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread jim holtman
If you run it under the profiler in RStudio, you will see that the 'lm' call is taking about 2 seconds longer in the function which might have to do with resolving the reference. So it is probably the function call in 'lapply' vs. the in-line statement in the 'for' loop that account for the differ

Re: [R] Help with optim function in R, please?

2017-08-07 Thread J C Nash
I haven't tried your code, but I've seen far too many attempts like this where there is no simple call to the function with starting parameters to see if a sensible answer is returned. If you get NaN or Inf or ... that isn't sensible, then you know it is not a good idea to try further. Beyond thi

Re: [R] Nested cross validation with lapply

2017-08-07 Thread Bert Gunter
This is an inappropriate question for this list. See the posting guide below and list archives for what is appropriate. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom Coun

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread Thierry Onkelinx
Dear Jesus, The difference is marginal when each code chunk does the same things. Your for loop does not yields the same output as the lapply. Here is the cleaned version of your code. n<-1 set.seed(123) x<-rnorm(n) y<-x+rnorm(n) rand.data<-data.frame(x,y) k<-100 samples <- split(sample(n), r

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread David L Carlson
A Google search on "lapply vs for r" or "lapply vs loop r" might have saved you some trouble. Many people have debunked this myth. Strangely they all start out with "everyone knows" or "it is commonly said that." I'm sure someone must have said it, but no one seems to be able to provide an autho

Re: [R] Nested for loop

2017-08-07 Thread Ben Tupper
Hmmm. If I understand you correctly, your question has to do with adding lines to your graph? If so, my ggplot2 skills are sort of floppy, but you could append your sampling results to your data frame (one for each sample set) and then simply add layers. Sort of like this. N <- 10 x <- 1:N d

Re: [R] Has For bucle be impooved in R

2017-08-07 Thread Jeff Newmiller
The lapply loop and the for loop have very similar speed characteristics. Differences seen are almost always due to how you use memory in the body of the loop. This fact is not new. You may be under the incorrect assumption that using lapply is somehow equivalent to "vectorization", which it is

[R] Has For bucle be impooved in R

2017-08-07 Thread Jesús Para Fernández
Hi! I am doing a lapply and for comparaison and I get that for is faster than lapply. What I have done: n<-10 set.seed(123) x<-rnorm(n) y<-x+rnorm(n) rand.data<-data.frame(x,y) k<-100 samples<-split(sample(1:n),rep(1:k,length=n)) res<-list() t<-Sys.time() for(i in 1:100){ modelo<-lm(y

Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-07 Thread S Ellison
> How can I draw a Hypercube sample for the variable mortality_probability so > that this variable exhibits the same pattern as the observed distribution? One simple way is to use the uniform random output of randomLHS as input to the quantile function for your desired distribution(s). For exa