Prev: Weibull distribution parameters
Next: mplay
From: Wayne King on 7 Sep 2009 15:13 "Kimberly " <kaporter79(a)hotmail.com> wrote in message <h838kv$484$1(a)fred.mathworks.com>... > Hello, > > I am trying to draw samples from 10 negative binomial distributions; I would like the distributions to have the same mean but different variances. Because you have to specify the parameters R and P to use nbinrnd, I have tried to use the following code to fix the mean and cycle through variances, and set the R and P values using the formula that relates them to the mean and variance. > > for i = 1:10; > reps = 100; > > mu = 350; > variance = 350+((i)*1000); > > pea = mu/variance*ones(reps,1); > argh = (mu^2/variance)/1-(mu/variance)*ones(reps,1); > > X = nbinrnd(argh,pea); > > end; > > It's not working. The means of the resulting distributions are not all 350 but instead move from about 250 to 350 as the variance increases. This has eaten up hours and hours and I am out of ideas. Any thoughts would be greatly, greatly appreciated. > > Thanks. Hi Kimberly, without going through your code, the mean and variance of a negative binomial both depend on R and P. The mean is R/P and the variance is R(1-P)/P^2, so I don't see how you can change the variance without changing the mean. There is no parameter (variable) in the variance that does not occur in the expression for the mean as well. Hope that helps, wayne
From: Kimberly on 7 Sep 2009 11:25 Hello, I am trying to draw samples from 10 negative binomial distributions; I would like the distributions to have the same mean but different variances. Because you have to specify the parameters R and P to use nbinrnd, I have tried to use the following code to fix the mean and cycle through variances, and set the R and P values using the formula that relates them to the mean and variance. for i = 1:10; reps = 100; mu = 350; variance = 350+((i)*1000); pea = mu/variance*ones(reps,1); argh = (mu^2/variance)/1-(mu/variance)*ones(reps,1); X = nbinrnd(argh,pea); end; It's not working. The means of the resulting distributions are not all 350 but instead move from about 250 to 350 as the variance increases. This has eaten up hours and hours and I am out of ideas. Any thoughts would be greatly, greatly appreciated. Thanks.
From: Kimberly on 7 Sep 2009 20:50 Thanks very much, Wayne. This was very helpful; it was starting to dawn on me that something was wrong beyond coding but I just couldn't put my finger on it. Bad news to be sure -- but a relief too... Thanks again, Kim "Wayne King" <wmkingty(a)gmail.com> wrote in message <h83lvt$a7s$1(a)fred.mathworks.com>... > "Kimberly " <kaporter79(a)hotmail.com> wrote in message <h838kv$484$1(a)fred.mathworks.com>... > > Hello, > > > > I am trying to draw samples from 10 negative binomial distributions; I would like the distributions to have the same mean but different variances. Because you have to specify the parameters R and P to use nbinrnd, I have tried to use the following code to fix the mean and cycle through variances, and set the R and P values using the formula that relates them to the mean and variance. > > > > for i = 1:10; > > reps = 100; > > > > mu = 350; > > variance = 350+((i)*1000); > > > > pea = mu/variance*ones(reps,1); > > argh = (mu^2/variance)/1-(mu/variance)*ones(reps,1); > > > > X = nbinrnd(argh,pea); > > > > end; > > > > It's not working. The means of the resulting distributions are not all 350 but instead move from about 250 to 350 as the variance increases. This has eaten up hours and hours and I am out of ideas. Any thoughts would be greatly, greatly appreciated. > > > > Thanks. > > Hi Kimberly, without going through your code, the mean and variance of a negative binomial both depend on R and P. The mean is R/P and the variance is R(1-P)/P^2, so I don't see how you can change the variance without changing the mean. There is no parameter (variable) in the variance that does not occur in the expression for the mean as well. > > Hope that helps, > wayne
From: Tom Lane on 9 Sep 2009 14:21 >> I am trying to draw samples from 10 negative binomial distributions; I >> would like the distributions to have the same mean but different >> variances. Because you have to specify the parameters R and P to use >> nbinrnd, I have tried to use the following code to fix the mean and cycle >> through variances, and set the R and P values using the formula that >> relates them to the mean and variance. > > Hi Kimberly, without going through your code, the mean and variance of a > negative binomial both depend on R and P. The mean is R/P and the variance > is R(1-P)/P^2, so I don't see how you can change the variance without > changing the mean. There is no parameter (variable) in the variance that > does not occur in the expression for the mean as well. That just means you don't keep one parameter fixed while adjusting the other. But you can keep the ratio R(1-P)/P fixed as you adjust P. (I believe this is the correct expression for the mean.) For example: p = [.5 .1 .05 .01]; % range of p values to try m = 5; % desired mean for j=1:4 r = m*p(j)/(1-p(j)); % r required to get this mean x = nbinrnd(r,p(j),10000,1); disp([mean(x), var(x)]) end Result: 4.9700 9.8449 5.0029 51.6987 4.9419 93.4337 4.7962 407.9411 -- Tom
|
Pages: 1 Prev: Weibull distribution parameters Next: mplay |