Hello Mario,
See replies inline below.
> On Mar 27, 2024, at 6:02 AM, Mario Ernst <
film...@gmail.com> wrote:
> When you say that it is an issue that the snm_1d can be arrived at from the two_epoch model by either setting T = 0 or nu = 1, do you mean to say that the results don't provide any meaningful information in terms of model selection? If so, is there a way around it?
In general, we want to use the Godambe approach to calculate the adjusted likelihood ratio accounting for linkage between the SNPs. That’s a little bit subtle in this case, because you can nest the snm model within the two_epoch model two ways.
> Alex mentioned that it is not possible to do AIC because the standard neutral model has no parameters but it would be possible to calculate the AIC as -2*log-likelihood of the model, right?
Correct.
> I am asking because I am running 1D models (snm_1d and two_epoch) for multiple populations and almost always the AIC supports the more complex models. However, the LRT never finds significant support for the complex model (the difference in the likelihoods is extremely low) and I am wondering why that is.
I’m a bit confused since your example showed a difference in log likelihood ~10^-10, which no method should ever say lends support to the more complex model.
Best,
Ryan
>
> Find below the code for one example population (and the respective fitted spectra attached):
>
> ######define the models
> def snm_1d(notused, ns, pts):
> """
> Standard neutral model.
> ns = (n1,)
> n1: Number of samples in resulting Spectrum
> pts: Number of grid points to use in integration.
> """
> xx = Numerics.default_grid(pts)
> phi = PhiManip.phi_1D(xx)
> fs = Spectrum.from_phi(phi, ns, (xx,))
> return fs
>
> snm_1d.__param_names__ = []
> snm = snm_1d
>
> def two_epoch(params, ns, pts):
> """
> Instantaneous size change some time ago.
> params = (nu,T)
> ns = (n1,)
> nu: Ratio of contemporary to ancient population size
> T: Time in the past at which size change happened (in units of 2*Na
> generations)
> n1: Number of samples in resulting Spectrum
> pts: Number of grid points to use in integration.
> """
> nu,T = params
> xx = Numerics.default_grid(pts)
> phi = PhiManip.phi_1D(xx)
> phi = Integration.one_pop(phi, xx, T, nu)
> fs = Spectrum.from_phi(phi, ns, (xx,))
> return fs
>
> two_epoch.__param_names__ = ['nu', 'T']
>
> def two_epoch_LRT(params, ns, pts):
> """
> Instantaneous size change some time ago.
> params = (nu,T)
> ns = (n1,)
> nu: Ratio of contemporary to ancient population size
> T: Time in the past at which size change happened (in units of 2*Na
> generations)
> n1: Number of samples in resulting Spectrum
> pts: Number of grid points to use in integration.
> """
> nu,T,theta = params
> xx = Numerics.default_grid(pts)
> phi = PhiManip.phi_1D(xx,theta0=theta)
> phi = Integration.one_pop(phi, xx, T, nu, theta0=theta)
> fs = Spectrum.from_phi(phi, ns, (xx,))
> return fs
>
> #calculate theta and likelihood for neutral model
> proj=[34]
> fs = dadi.Spectrum.from_data_dict(dd, [pop], polarized = False,projections = proj)
> ns = fs.sample_sizes
> pts = [max(ns)+300, max(ns)+350, max(ns)+400]
> func_ex = dadi.Numerics.make_extrap_log_func(snm_1d)
> model_fit = func_ex([], ns, pts)
> ll_neutral = dadi.Inference.ll_multinom(model_fit, data) #ll_neutral=-74.47790204264794
> theta = dadi.Inference.optimal_sfs_scaling(model_fit, data) #theta=820.9806169050971
>
> #run the models as if the scenario was neutral
> func_ex_two_epoch = dadi.Numerics.make_extrap_log_func(two_epoch_LRT)
> popt_two_epoch=[ 1, 0.8396 , 820.98061691] #Ne=1, T=0.8396 is optimised param for two_epoch model elsewhere, theta=820.98061691 calculated above for snm_1d
> model_two_epoch = func_ex_two_epoch(popt_two_epoch, ns, pts)
> ll_two_epoch = dadi.Inference.ll(model_two_epoch, fs) #ll_two_epoch=-74.47790204244299
>
> #degrees of freedom: 2 (as Ne and T are added to the snm_1d model)
> #LRT statistic: 2*(ll_two_epoch-ll_neutral)=4.098978934052866e-10
> #critical value (p<0.05)=5.991, hence not significant
>
> All the best, Mario
> To view this discussion on the web visit
https://groups.google.com/d/msgid/dadi-user/6c43cec0-289d-4c21-9d57-dcda1dc96a49n%40googlegroups.com.
> <fitted_alleni_r70_pop2_reps_50_50_100_maxiters_100_100_100_folds_3_2_1_two_epoch.pdf><fitted_alleni_r70_pop2_reps_50_50_100_maxiters_100_100_100_folds_3_2_1_snm_1d.pdf>