0

I want to make a vector/data list of a new set of values derived from 3 different distributions, two are lnorm and 1 is a mixed uniform distribution. I need to sum generated values of each of these distributions into one value (v1+v2+v3), in order to fit a distribution to the sum of the 3 distributions.

My code does not summarize the sum of distributions into one dataset (with function: list) and I am unsure whether the UnivarMixingDistribution function part of the code works? I want it to generate one value and save it into xv3 and add it to the two other values.

Error shown is:

In e[i] <- list(v1, v2, xv3) :
  number of items to replace is not a multiple of replacement length

code:

e <- list(mode="vector",length=n)
for(i in 1:1000){
    v1=rlnorm(n, mean, sd) #simulate values for lnorm distribution
    v2=rlnorm(n, mean, sd)
    v3=myMixv4<-UnivarMixingDistribution(Unif(Min=, Max=), #1st distribution
                                         Unif(Min=, Max=), #2nd distribution
                                         mixCoeff=c((ND/n),
                                                    (Detected/n)))
    rmyMixv3<-r(myMixv3)
    xv3 <- rmyMixv3(1)
    e[i] <- list(v1,v2,xv3)
}
IRTFM
  • 240,863
  • 19
  • 328
  • 451
Kristian
  • 1
  • 4
  • 2
    I suggest `replicate` or `lapply` instead of a `for` loop. Take a look [here](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames/24376207#24376207), substituting in general *"data frames"* with your *"list of lists"* concept, and I think you'll be fine. But if you really want the loop, try `e[[i]] – r2evans Apr 24 '18 at 21:08
  • "Sums" of distributions are not the same as mixtures. But appears you know that. What's missing at the moment are lines of code that define `mean`, `sd` and `n`. (Really bad naming practice by the way.) Try to fill in missing bits in the code above. I would have guessed you wanted `e – IRTFM Apr 24 '18 at 22:37
  • Thanks for the help, code works now! – Kristian May 02 '18 at 01:50

0 Answers0