I’m using Pymc3 to fit a hierarchical model for concentration of a drug. The model should include sex as a covariate.

Our model posits that concentration of drug, conditioned on parameters, should look like…

C(t) = \dfrac{2.5}{V} \dfrac{k}{k-k_a}\left( e^{-kt} - e^{k_at}\right).

Here, V,k, k_a are all parameters which are modeled heirarchically. I would like to model the mean of each of these parameters as a function of sex.

The data I have consist of 36 patients sampled at 8 time points. I am currently ignoring the fact that measurements come from different patients (that will come at a later time) and instead imagining I have 2 patients (one male, one female) who have provided these measurements. Here is my data.

Here is how I construct my model

```
df = pd.read_csv('Data/ApixibanExperimentData.csv').query('Time>0')
#Rescaled to mg/L
Time= df.Time.values
Concentration_hat = df.Concentration.values*10e-3
sample_times = np.sort(np.unique(Time))
Sex = df.Sex.apply(lambda x: 1 if x=='Male' else 0).values
Sex = np.c_[np.ones_like(Sex),Sex]
with pm.Model() as model1:
D = 2.5 #Dose in mg
#Sex Effects
beta_k_a_sex = pm.Normal('ß_k_a_sex', 0,1, shape = 2)
beta_k_sex = pm.Normal('ß_k_sex', 0,1, shape = 2)
beta_V_sex = pm.Normal('V_sex', 0,1, shape = 2)
#PKPD parameters
k_a = pm.TruncatedNormal('k_a',pm.math.exp(pm.math.dot(Sex,beta_k_a_sex)),1, lower = 0)
k = pm.TruncatedNormal('k',pm.math.exp(pm.math.dot(Sex,beta_k_sex)),1, lower = 0)
#Volume of the absorptive compartment
V = pm.TruncatedNormal('V',pm.math.exp(pm.math.dot(Sex,beta_V_sex)),1,lower = 0)
sigma = pm.HalfCauchy('sigma',1)
#Analytic solution to the ODE
solution = (D/V)*(k_a/(k-k_a))*(tt.exp(-k_a*Time) - tt.exp(-k*Time))
#Convienience
solution_samp = (D/V)*(k_a/(k-k_a))*(tt.exp(-k_a*sample_times) - tt.exp(-k*sample_times))
C = pm.Deterministic('C',solution)
Cs = pm.Deterministic('Cs', solution_samp)
Y = pm.Lognormal('Y', mu = tt.log(C), sd = sigma, observed = Concentration_hat )
trace = pm.sample(2000, tune = 500, chains = 4)
ppc = pm.sample_ppc(trace)
```

# Problem

After sampling, the male and female curves look exactly the same, which leads me to believe I have improperly specified my model.

Have I set up my model correctly? Will `solution`

give me two curves, depending on the sex of the patient? If not, how can I correct my model?