5
$\begingroup$

I'm trying to sample $100$ numbers from the Geometric$(0.3)$ distribution, and $100$ numbers from the Geometric$(0.6)$ distribution, and compute $$\frac{\text{number of times Geom(0.3) value = Geom(0.6) value}}{100}$$ My approach is to do

{RandomVariate[GeometricDistribution[0.3], 100], RandomVariate[GeometricDistribution[0.5], 100]}

which creates a list of two lists, one containing the samples from Geom(0.3) and the other containing the samples from Geom(0.6). Now I just need to count how many times the $i$th element of the two lists are equal. How can I do that? Or is there a better way to do this whole sampling thing?

$\endgroup$
0

6 Answers 6

12
$\begingroup$
dist1=RandomVariate[GeometricDistribution[0.3], 100];
dist2= RandomVariate[GeometricDistribution[0.6], 100];

Count[dist1-dist2,0]

Total@UnitBox[dist1-dist2]
$\endgroup$
4
$\begingroup$
SeedRandom[0];

a = RandomVariate[GeometricDistribution[0.3], 10];
b = RandomVariate[GeometricDistribution[0.6], 10];

c = Transpose[{a, b}]

{{1, 2}, {1, 0}, {1, 0}, {1, 0}, {0, 1}, {0, 0}, {4, 0}, {1, 4}, {6, 0}, {1, 1}}

Count[{x_, x_}] @ c

2

SequenceCount[c, {x_} /; Equal @@ x]

2

$\endgroup$
4
$\begingroup$
a = RandomVariate[GeometricDistribution[0.3], 10];
b = RandomVariate[GeometricDistribution[0.6], 10];

c = Transpose[{a, b}]

{{1, 2}, {1, 0}, {1, 0}, {1, 0}, {0, 1}, {0, 0}, {4, 0}, {1, 4}, {6, 0}, {1, 1}}

Grabbing the @eldo's data and using Cases:

Length@Cases[c, {x_ ..}]

2

$\endgroup$
4
$\begingroup$

Grabbing @eldo's data:

SeedRandom[0];

a = RandomVariate[GeometricDistribution[0.3], 10];
b = RandomVariate[GeometricDistribution[0.6], 10];

c = Transpose[{a, b}]

(* {{1, 2}, {1, 0}, {1, 0}, {1, 0}, {0, 1}, {0, 0}, {4, 0}, {1, 4}, {6, 0}, {1, 1}} *) 
Total[MapApply[KroneckerDelta]@c]

(* 2 *) 

Or:

MapThread[KroneckerDelta, {a, b}] // Total

(* 2 *) 
$\endgroup$
3
$\begingroup$
m = RandomInteger[GeometricDistribution[0.3], {100, 2}];
Count[ Equal @@@ m, True]
$\endgroup$
3
$\begingroup$
SeedRandom[0];
a = RandomVariate[GeometricDistribution[0.3], 10];
b = RandomVariate[GeometricDistribution[0.6], 10]; (* Thanks @eldo )

Subtract @@ {a, b} // Unitize // Count[0]
Count[True]@MapThread[#1 === #2 &, {a, b}]
Count[True][Equal @@@ Transpose[{a, b}]]
ArrayReduce[Apply@SameQ, {a, b}, 1]

2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.