Jump to Content
Version 1.6.2-51  

Confidence Contours

 

Here's a short script which generates Chi-square confidence contours of the best fit Gaussian center vs. sigma using fake data:


        % To make this example self-contained,
        % we'll generate fake data --
        % here we load a few routines to do that.

    () = evalfile ("init_contours.sl");

        % Fit the fake data with a Gaussian...

    () = fit_counts();

        % .. generate confidence contours..

    px = conf_grid ("gauss(1).center", 11.985, 12.018, 50);
    py = conf_grid ("gauss(1).sigma", 0.015, 0.045, 50);

    gc = conf_map_counts (px, py);

        % and plot:

    id = plot_open ("ex_contours.ps/cps");

    xrange (11.985,12.015);
    yrange (0.015, 0.035);

    xlabel ("Line Center [\\A]");
    ylabel (latex2pg("\\sigma") + " [\\A]");
    title ("\"Random\" data vs. \"Ideal\" data");

    plot_conf (gc);

      % One can also save the contours as a FITS image:

    save_conf (gc, "gc.fits");



Making plots with overlaid confidence contours is easy. Continuing the above example, we generate confidence contours for another fake data set and overlay them:

        % For comparison, we'll generate an "ideal" random dataset
        % (ideal in the sense that its best-fit
        % center value exactly matches the model center).

    generate_ideal_random_dataset (Lo, Hi);

        % Generate confidence contours for a Gaussian fit
        % to this "ideal" dataset:
        % (for fun, we'll use a different grid)

    py = conf_grid ("gauss(1).sigma", 0.015, 0.045, 64);
    ic = conf_map_counts (px, py);

        %  Now overplot those confidence contours to
        %  compare with the ones from the "random" data

    oplot_conf (ic);
    plot_close (id);

        % To compare with the contour plots,
        % generate N random datasets, fit a Gaussian to each,
        % and plot the distribution of best-fit center values:

    fit_random_datasets (Lo, Hi, 10000);

Here's the resulting confidence contour plot and a histogram of the best-fit center positions for 10000 datasets randomly generated from the same model.

Accessibility  |  Made with JED  |  Best Viewed with a Browser  |  Valid HTML 4.01  |  Valid CSS ]
This page is maintained by John C. Houck.   Last updated: Apr 3, 2022