r - Trying to create a function for a 3-component normal mixture distribution -


i trying create r function generate samples 3-component normal mixture distribution 3 different parameters keep getting error messages.

here current code

normal.mixture = function(n, mu1, sig1, w1, mu2, sig2, w2, mu3, sig3, w3) {     p = c(w1, w2, w3)     x=vector(mode="numeric", length=n)        (i in 1:n) {           j = sample(c(1,2,3), 1, prob=p)           if (j==1) {               x[i] rnorm(1, mu1, sig1)           }           else if (j==2) {               x[i] = rnorm(1, mu2, sig2)           }           else {               x[i] = rnorm(1, mu3, sig3)           }        }     x } 

think you're missing equals sign

  if (j==1) {           x[i] = rnorm(1, mu1, sig1)   } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -