I have a data set I'd like to adjust with 2 parameters, then compare that to another set of data. By using NMaximixe
with DistributionFitTest
, I'm able to determine the best fit of parameters. Great, now I'd like to do something like plot a ContourPlot
of the 2D parameter space to show a 1-sigma, 2-sigma, and 3-sigma confidence interval for possible choices of parameters.
However, DistributionFitTest
only returns P-values and test statistics. I am still a complete noob when it comes to stats, so I have no idea how to determine confidence intervals from this...
A quick example that you can copy and paste:
Clear["Global`*"]
NumPerSet = 1000;
(* This is the first "double-hump" distribution *)
set1 = RandomVariate[NormalDistribution[6, 1.2], NumPerSet];
set2 = RandomVariate[NormalDistribution[11, 1.2], NumPerSet];
data1 = Join[set1, set2];
(* This is like data1 but "shifted" to the left by 1 *)
set3 = RandomVariate[NormalDistribution[5, 1.2], NumPerSet];
set4 = RandomVariate[NormalDistribution[10, 1.2], NumPerSet];
data2 = Join[set3, set4];
(* Now apply a scale factor to the data2 set *)
data2 = data2 0.9;
(* Create some plottable distributions *)
skd1 = KernelMixtureDistribution[data1];
skd2 = KernelMixtureDistribution[data2];
(* Show each distribution and the associated histogram *)
Show[Plot[{PDF[skd1, x], PDF[skd2, x]}, {x, 0, 15}, Frame -> True, PlotLabel -> "The Setup"], Histogram[{data1, data2}, Automatic, "PDF", ChartLegends -> {"data1", "data2"}]]
(* Now show a plot of the parameter space, where the peak should be around x = 1, y = 0.9 *)
ContourPlot[DistributionFitTest[(data1 - shift) scale, skd2, "PValue"], {shift, 0.8, 1.2}, {scale, 0.8, 1}]
I could spit out a test statistic for a grid of points instead (and try to fit lines to this), but I don't know how to calculate the confidence interval from P-values or test statistics. Is there a built-in method, or a way I could even brute force it?
Thanks in advance!