# Exam data - inference of student performance

**URL:** <https://discourse.pymc.io/t/exam-data-inference-of-student-performance/4955>\
**Category:** Questions\
**Created:** [April 27, 2020, 4:54pm UTC](https://discourse.pymc.io/t/exam-data-inference-of-student-performance/4955 "2020-04-27T16:54:15Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![RCHA](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@RCHA](https://discourse.pymc.io/u/RCHA)\
**Post date:** [April 28, 2020, 8:22pm UTC](https://discourse.pymc.io/t/exam-data-inference-of-student-performance/4955/3 "2020-04-28T20:22:04Z")

</div>

Super - thanks. Your post made me realise that I wasn’t passing test\_value the sampler. This meant it was starting in a region of zero probability (logp = -inf), so the sampler breaks, naturally.

[This helpful post](https://discourse.pymc.io/t/get-nan-or-inf-from-model-logp-model-test-point-is-an-attestation-of-incorrectly-configured-model/111/11?) mentioned using a test\_value for a binomial distribution.

So the code works, now, _provided there are no missing values in the data_. However, if I make the observed data n a masked array, then the code breaks:

> File “main.py”, line 43, in   
> nH\_obs = n - nE ## Observed number of hard questions answered correctly, given nE  
> File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/theano/tensor/var.py”, line 230, in **rsub**  
> return theano.tensor.basic.sub(other, self)  
> File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/theano/gof/op.py”, line 615, in **call**  
> node = self.make\_node(\*inputs, \*\*kwargs)  
> File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/theano/tensor/elemwise.py”, line 480, in make\_node  
> inputs = list(map(as\_tensor\_variable, inputs))  
> File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/theano/tensor/basic.py”, line 194, in as\_tensor\_variable  
> return constant(x, name=name, ndim=ndim)  
> File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/theano/tensor/basic.py”, line 232, in constant  
> x\_ = scal.convert(x, dtype=dtype)  
> File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/theano/scalar/basic.py”, line 284, in convert  
> assert type(x\_) in [np.ndarray, np.memmap]  
> AssertionError

It looks like I am not allowed to subtract a pymc3.model.FreeRV object from a masked numpy array (but a normal ndarray is fine); do you know if there is a reason for this?

Here’s the full code:

> data = pd.read\_csv( ‘test\_data.csv’, header = [0,1], index\_col = 0 )  
> data.fillna(-1, inplace=True)  
> data = data.astype( ‘int32’ )  
> print(data)  
> S = len(data.index) ## Number of students  
> T = len(data.columns) ## Number of tests  
> N = np.array( data.columns.get\_level\_values(1).values, dtype = int ) ## Max available marks for each test  
> n = data.to\_numpy()  
> n = np.ma.masked\_equal(n, value=-1)

> with pm.Model() as model:

```
    H = pm.DiscreteUniform('H', lower = np.zeros(T, dtype = int), upper = N, shape = T, testval = N//2 )
    E = N - H
    pE = pm.Uniform('pE', lower = 0., upper = 1., shape=S)
    pH = pm.Uniform('pH', lower = 0., upper = pE, shape=S)
    nE = pm.Binomial('nE', n=E[None,:], p=pE[:,None], shape = (S, T), testval = n//2 )
    nH_obs = n - nE ## Observed number of hard questions answered correctly, given nE
    nH = pm.Binomial('nH', n=H[None,:], p=pH[:,None], shape = (S, T), observed = nH_obs )
    trace = pm.sample(5000, tune = 10000, discard_tuned_samples = True )

```

Many thanks for taking the time to look at this.

---

_[View the full topic](https://discourse.pymc.io/t/exam-data-inference-of-student-performance/4955)._
