load(distrib);

load(draw);

quantile_normal(0.975,0,1);

/* graph 1: non-probabilistic samples */
t1: 0.7$
t2: 1.5$
t3: 2.3$
draw2d(
terminal = 'png,
file_name = "~/h_test01",
xtics = true,
xtics_axis = true,
ytics = false,
axis_top    = false,
axis_left  = false,
axis_right  = false,
yaxis = true,

 /* filled parts */
 filled_func = true,
 fill_color  = light-green,
 explicit(pdf_normal(x,0,1),x,-3,-1.96),
 explicit(pdf_normal(x,0,1),x,1.96,3),

 /* not filled parts */
 filled_func = false,
 line_width=2,

 color=green,
 explicit(pdf_normal(x,0,1),x,-3,3),

 color = blue,
 parametric(t1,t,t,0,pdf_normal(0,0,1)),
 point_type=filled_circle,
 point_size=2,
 points([[t1,0]]),

 color = purple,
 parametric(t2,t,t,0,pdf_normal(0,0,1)),
 point_type=filled_circle,
 point_size=2,
 points([[t2,0]]),

 color = red,
 parametric(t3,t,t,0,pdf_normal(0,0,1)),
 point_type=filled_circle,
 point_size=2,
 points([[t3,0]])
);

/* graph 2: N(1.5, 0.4) sample */
t1: 1.5$
s1: 0.4$

draw2d(
terminal = 'png,
file_name = "~/h_test02",
xtics = true,
xtics_axis = true,
ytics = false,
axis_top    = false,
axis_left  = false,
axis_right  = false,
yaxis = true,

 /* filled parts */
 filled_func = true,
 fill_color  = light-green,
 explicit(pdf_normal(x,0,1),x,-3,-1.96),
 explicit(pdf_normal(x,0,1),x,1.96,3),

 fill_color = pink,
 explicit(pdf_normal(x,t1,s1)*s1,x,1.96,3),

 fill_color = gold,
 explicit(min(pdf_normal(x,0,1),pdf_normal(x,t1,s1)*s1),x,1.96,3),

 /* not filled parts */
 filled_func = false,
 line_width=2,

 color = dark-pink,
 explicit(pdf_normal(x,t1,s1)*s1,x,-3,4),

 color = red,
 parametric(t1,t,t,0,pdf_normal(0,0,1)),
 point_type=filled_circle,
 point_size=2,
 points([[t1,0]]),

 color=green,
 explicit(pdf_normal(x,0,1),x,-3,4)
);

/*1-beta*/
1-cdf_normal(1.96,t1,s1),numer;

/* graph 3: N(2.5, 1.5) sample */
t1: 2.5$
s1: 1$

draw2d(
terminal = 'png,
file_name = "~/h_test03",
xtics = true,
xtics_axis = true,
ytics = false,
axis_top    = false,
axis_left  = false,
axis_right  = false,
yaxis = true,

 /* filled parts */
 filled_func = true,
 fill_color  = light-green,
 explicit(pdf_normal(x,0,1),x,-3,-1.96),
 explicit(pdf_normal(x,0,1),x,1.96,5),

 fill_color = violet,
 explicit(pdf_normal(x,t1,s1)*s1,x,-3,1.96),

 /* not filled parts */
 filled_func = false,
 line_width=2,

 color = dark-pink,
 explicit(pdf_normal(x,t1,s1)*s1,x,-3,5),

 color = red,
 parametric(t1,t,t,0,pdf_normal(0,0,1)),
 point_type=filled_circle,
 point_size=2,
 points([[t1,0]]),

 color=green,
 explicit(pdf_normal(x,0,1),x,-3,5)
);

/*1-beta*/
cdf_normal(1.96,t1,s1),numer;

/*beta*/
1-%;

quantile_normal(0.525,0,1);

/*graph 4: critical region at center*/
draw2d(
terminal = 'png,
file_name = "~/h_test04",
xtics = true,
xtics_axis = true,
ytics = false,
axis_top    = false,
axis_left  = false,
axis_right  = false,
yaxis = true,

 /*this eliminates tics on top*/
 point_size=0,
 points([[0,0]]),

 /* filled parts */
 filled_func = true,
 fill_color  = light-green,
 explicit(pdf_normal(x,0,1),x,-0.0627,0.0627),

 /* not filled parts */
 filled_func = false,
 line_width=2,

 color=green,
 explicit(pdf_normal(x,0,1),x,-3,3)
);

/*graph 5: chi^2 dist*/
chi0: 2$
chi1: 4$
t1: 3$
t2: 5$
t3: 7$

draw2d(
terminal = 'png,
file_name = "~/h_test05",
xtics = true,
xtics_axis = true,
ytics = false,
axis_top    = false,
axis_left  = false,
axis_right  = false,
yaxis = true,

 /* filled parts */
 filled_func = true,
 fill_color  = light-green,
 explicit(pdf_chi2(x,chi0),x,quantile_chi2(0.95,chi0),10),

 /* not filled parts */
 filled_func = false,
 line_width=2,

 color=green,
 explicit(pdf_chi2(x,chi0),x,0,10),

 color = blue,
 parametric(t1,t,t,0,0.5),
 point_type=filled_circle,
 point_size=2,
 points([[t1,0]]),

 color = purple,
 parametric(t2,t,t,0,0.5),
 point_type=filled_circle,
 point_size=2,
 points([[t2,0]]),

 color = red,
 parametric(t3,t,t,0,0.5),
 point_type=filled_circle,
 point_size=2,
 points([[t3,0]])
);

1-cdf_chi2(quantile_chi2(0.95,chi0),chi1);

/*graph 6: chi^2 dist(sample dist filled)*/
draw2d(
terminal = 'png,
file_name = "~/h_test06",
xtics = true,
xtics_axis = true,
ytics = false,
axis_top    = false,
axis_left  = false,
axis_right  = false,
yaxis = true,

 /* filled parts */
 filled_func = true,
 fill_color  = light-green,
 explicit(pdf_chi2(x,chi0),x,quantile_chi2(0.95,chi0),10),

 fill_color = violet,
 explicit(pdf_chi2(x,chi1),x,0,quantile_chi2(0.95,chi0)),

 fill_color = pink,
 explicit(pdf_chi2(x,chi1),x,quantile_chi2(0.95,chi0),10),

 fill_color = gold,
 explicit(min(pdf_chi2(x,chi0),pdf_chi2(x,chi1)),x,quantile_chi2(0.95,chi0),10),

 /* not filled parts */
 filled_func = false,
 line_width=2,

 color = dark-pink,
 explicit(pdf_chi2(x,chi1),x,0,10),

 color=green,
 explicit(pdf_chi2(x,chi0),x,0,10),

 color = blue,
 parametric(t1,t,t,0,pdf_chi2(t1,chi1)),
 point_type=filled_circle,
 point_size=2,
 points([[t1,0]]),

 color = purple,
 parametric(t2,t,t,0,pdf_chi2(t2,chi1)),
 point_type=filled_circle,
 point_size=2,
 points([[t2,0]]),

 color = red,
 parametric(t3,t,t,0,pdf_chi2(t3,chi1)),
 point_type=filled_circle,
 point_size=2,
 points([[t3,0]])
);