import numpy as np
= np.array([0.1, 0.3, 0.6])
theta = 1000
size 1)
np.random.seed(= np.random.multinomial(1, theta, size=size)
xs print(xs)
[[0 1 0]
[0 0 1]
[0 0 1]
...
[0 1 0]
[1 0 0]
[0 0 1]]
Application: sample ratio mismatch.
Consider a new experimental unit \(n\) is assigned to one of \(i \in \{1, 2, 3\}\) groups with probabilities \(\mathbf{\theta} = [0.1, 0.3, 0.6]\). Therefore, groups are \(\mathrm{Multinomial}(1, \mathbf{\theta})\) distributed.
import numpy as np
theta = np.array([0.1, 0.3, 0.6])
size = 1000
np.random.seed(1)
xs = np.random.multinomial(1, theta, size=size)
print(xs)
[[0 1 0]
[0 0 1]
[0 0 1]
...
[0 1 0]
[1 0 0]
[0 0 1]]
We can test the hypothesis
\[ \begin{align} H_0: \mathbf{\theta} = \mathbf{\theta_0} \\ H_1: \mathbf{\theta} \neq \mathbf{\theta_0} \end{align} \]
with \(\mathbf{\theta_0} = [0.1, 0.4, 0.5]\) and estimate \((1 - \alpha)\) confidence sequences for \(\mathbf{\theta}\) using the Multinomial
test:
from savvi.multinomial import Multinomial
alpha = 0.05
theta_0 = np.array([0.1, 0.4, 0.5])
multinomial = Multinomial(alpha, theta_0)
AttributeError: _ARRAY_API not found
(CVXPY) Oct 24 05:36:17 PM: Encountered unexpected exception importing solver ECOS:
ImportError('numpy.core.multiarray failed to import')
(CVXPY) Oct 24 05:36:17 PM: Encountered unexpected exception importing solver SCS:
ImportError('numpy.core.multiarray failed to import')
(CVXPY) Oct 24 05:36:17 PM: Encountered unexpected exception importing solver ECOS_BB:
ImportError('numpy.core.multiarray failed to import')
(CVXPY) Oct 24 05:36:17 PM: Encountered unexpected exception importing solver OSQP:
ImportError('numpy.core.multiarray failed to import')
AttributeError: _ARRAY_API not found
AttributeError: _ARRAY_API not found
AttributeError: _ARRAY_API not found
For each new unit sample \(n\), we run the test. If \(p_n < \alpha\), we have the option to stop running: