I'm resending my message which was delivered with an incorrect title.
I'm trying to generate a random variable with a distribution slightly
different from the standard uniform distribution. Specifically, I want 50%
of the numbers to become twice likely, than the rest 50%, to be generated.
Does anyone have experience doing this in SPSS? Any suggestions would be
greatly appreciated. For simplicity, let's try to generate 1000 discrete
numbers, in the range of 1 and 4. The last column (labeled "??") of the
following frequency table depicts what I am trying to get.
# uniform ??
1 .25 .167
2 .25 .167
3 .25 .333
4 .25 .333
I can think of a mechanical but tedious way:
Step 1) Generate six cases, instead of four, from the uniform distribution.
So, each case has a probability of 1/6 = .167 to be generated.
Step 2) Recode cases #5 and #6 into cases #3 and #4, respectively. See the
following.
# uniform recoded
1 .167 .167
2 .167 .167
3 .167 .333
4 .167 .333
5 .167
6 .167
Is there a known distribution in SPSS that can generate the above random
numbers?
Sincerely,
Chris Chiu
You have 2 populations, A and B. The probability that random variable X
equals some value x is:
P(X=x) = P(A)*P(X=x|A) + P(B)*P(X=x|B).
There are actually several ways of defining the distribution of X
in A and B that could result in the overall dist. that you want.
The most straightforward is that A has a probability of .333 and
can take the values of 1 or 2 with equal probability. B has a
probability
of .667 and can take the values of 3 or 4 with equal probability.
An alternate mixture would have A with a prob. of .667,
taking the values of integers 1 to 4 with equal probability; B with a
prob.
of .333, taking the values of 3 or 4 with equal probability.
In this latter case, the 2 component distributions overlap.
The following code illustrates the generation of the mixture
distribution
for each of the above 2 mixture arrangements, in turn. The basic
strategy
is to first generate a random variable that determines the case's
population membership. Then, for each pop. (group), have a
statement that generates X, conditional on membership in that group.
I hope this helps. I believe a good source on mixture distributions
is "Finite Mixture Distributions" by Everitt & Hand. I don't have it on
my shelf at the moment, but I think it was published by Chapman and
Hall,
sometime in the '80s.
David Matheson
SPSS Statistical Support.
* mixture of nonoverlapping discrete dist.
input program.
loop id = 1 to 1000.
compute gp = (uniform(1) <= 2/3) + 1.
if (gp = 1) x = trunc(uniform(2)) + 1.
if (gp = 2) x = trunc(uniform(2)) + 3.
end case.
end loop.
end file.
end input program.
execute.
* mixture of overlapping discrete dist.
input program.
loop id = 1 to 1000.
compute gp = (uniform(1) <= 1/3) + 1.
if (gp = 1) x = trunc(uniform(4)) + 1.
if (gp = 2) x = trunc(uniform(2)) + 3.
end case.
end loop.
end file.
end input program.
execute.
compute arandvar = 4 - mod(trunc(rv.uniform(0,6)),4).
trunc(rv.uniform(0,6)) gives an integer between 0 and 5 inclusive.
Uniform(6) is equivalent to rv.uniform(0,6) in versions prior to 8. The
mod(...,4) converts 4 and 5 to 0 and 1 respectively, making these two latter
values twice as likely as 2 and 3. Finally, sustracting from 4 puts the
likely values at the top of the range.
chris chiu wrote in message
<3.0.32.19980706...@pilot.msu.edu>...
I would approach this as a case of generating data from a multinomial
distribution. A standard algorithm for doing this, which I've
rendered in SPSS (and used many times), appears below:
input program .
loop #i = 1 to NumberOfCasesDesired.
+ compute #rand = rv.uniform(0,1) .
+ do if (#rand <=0.167)
+ compute X = 1 .
+ else if (#rand <= 0.334) . /* =.167 + .167
+ compute X = 2 .
+ else if (#rand <= 0.667) . /* =.167 + .167 + .333
+ compute X = 3 .
+ else .
+ compute X = 4 .
+ end if .
* .
end case .
end loop .
end file .
end input program .
Regards,
--
=-=-=-=-=-=-=-=-=-==-=-=-=
Mike Lacy, Sociology Dept., Colo. State Univ. FT COLLINS CO 80523
voice (970) 491-6721 fax (970) 491-2191