Code:

```
llhood2 <- function(theta, c, c11,c12,c22){
s<-theta[1]
d<-theta[2]
P11 = (1 - ((s * (1 - c) * (1 - c + (2 * d * c)))) / (4 - (s * (1 + (2 * d))))
P22 = (1 - (s * c * ((2 * d * (1 - c)) + c))) / (4 - (s * (1 + (2 * d))))
P12 = (1 - P11 - P22)
logL = c11*log(P11) + c12*log(P12) + c22*log(P22)
-logL
}
```

Using the optim function in R and plugging in genotype data from each environment, I am able to get a point estimate for s and d in one environment (s1 and d1) and the variance of these estimates from the hessian, then I get parameter estimates using genotype data from the 2nd environment,(s2 and d2, and thier associated variances). So, two separate fittings of the model give me s1 var_s_1 and s2 var_s_2, etc. The Code for optim is below:

Code:

```
fit1 <- optim(inits, llhood, method="L-BFGS-B", hessian=T, lower=lower, upper=upper,
c=c,c11=c11,c12=c12,c22=c22, control=list(trace=1))
fit2 <- optim(inits, llhood, method="L-BFGS-B", hessian=T, lower=lower, upper=upper,
c=c,c11=n11,c12=n12,c22=n22, control=list(trace=1)
```

Ive also considered a likelihood ratio test where I test whether the difference between the two estimates of s1 and s2, is not different from zero (s1= s2 ,reduced model) vs different from zero. But I'm not sure how to set this up given my likelihood equations (i.e how to get ML estimates in both environments simultaneously). An added wrinkle is that I have two unknowns, s and d, both of which Id like to test for significant differences between the two environments. So would I need to fix one, to test for the other?

Any specific help would be much appreciated.

Louis