\begindata{text, 204354}
\textdsversion{11}
\template{default}
\define{invisible
}
\define{zserif
menu:[Font,Andy]
attr:[FontFamily Andy Int 0]}
\define{zsans
menu:[Font,AndySans]
attr:[FontFamily AndySans Int 0]}
\define{zfixed
menu:[Font,AndyFixed]
attr:[FontFamily AndyFixed Int 0]}
\define{zsymbol
menu:[Font,AndySymbol]
attr:[FontFamily AndySymbol Int 0]}
$syntaxlevel 1
*Module for Linear Regression
\flushleft{define	}\flushleft{\tim{i: i,n,flag,j,l,sf(1:3),cc,xcalc,n0,cc0,xcalc0,xcol,ycol,flag2
	f: Sx,Sy,Sxy,Sx2,st,s(0:30),a1,b1,a,b,x1,y1,lastx,lasty,m,int,d,eb,em,xave,yave,sdx,sdyx,clmp,clmp1,x0,studT,k,k1,sig,t(-40:40)
font	zsans,25
fine	500,400
rescale	TRUE,TRUE,TRUE,TRUE

unit	genesis
calc	xcalc:=4	$$ point of limit sampling
	cc:=95	$$ confidence coeffcient.
	studT:=1.71	$$ T distribution value
	n:=25	$$ no. sampled points
jump	cover

unit	cover
}}\flushleft{menu	Title: pre0
}menu	Least Squares Fit: pre2
menu	Least Squares Fit Sample:pre2a
menu	Confidence Limits Assumptions: pre3
menu	Confidence Limits for Slope: pre4
menu	Confidence Limits for Slope Sample: pre4aa
menu	Confidence Limits for Mean:pre4half
menu	Confidence Limits for Mean Sample:pre4a
menu	Confidence Limits Conclusion: pre5
menu	Prediction Limits: pre6
menu	Prediction Limits Sample:pre6a
menu	Conclusion: pre7
menu	Supplemental Information: pre8
next 	pg2

text
\center{Tutorial on:
}\bold{\bigger{\center{Linear Regression, Confidence Limits for a Population Mean, and Prediction Limits for One More Observation}}}\center{

Frank McClintock, Terence Chow, Louis L. Bucciarelli
Spring 1991


This module is to provide educational information on statistical analysis and to illustrate concepts in statistical analysis.
\\
}do 	nextscr
jump	pg2

unit 	pg2
next 	sample
back	cover
text
Linear regression is used to fit a linear relation between two variables, from pairs of corresponding data points.  The coefficients \italic{\tim{a}}\tim{ and }\italic{\tim{b}}\tim{ }of a  line  \italic{\tim{y = a + bx}} are chosen to minimize the sum of the squares of \italic{\tim{y}}-errors between the data points and the line; that is, we choose \italic{a} and \italic{b} to minimize:
\flushleft{
}\italic{\center{\symb{S}}}\center{(}\italic{\center{y}}\italic{\subscript{\center{\tim{i}}}}\italic{\center{ - }}\center{(}\italic{\center{a + bx}}\italic{\subscript{\center{\tim{i}}}}\center{))}\superscript{\center{2}}\center{.

}This line is referred to as a \italic{least squares fit}.  A least squares fit is performed on a \italic{sample}, a finite collection of data points.  A sample is a subset of the \italic{population}, an infinite set of data.
\flushleft{\\
do 	nextscr
jump	sample

unit 	pg3
next	pg4
back	sample
text
}Although the infinite population itself cannot be found from a finite sample, \italic{confidence limits} for the slope and for  the mean value of the population at any \italic{x} can be found from the sample.  First however, make four assumptions about the infinite population and the relative errors:
	1. at any \italic{x}, the values of \italic{y} are normally distributed about the mean value of \italic{y},
	2. the mean value of\italic{ y} is a linear function of \italic{x},
	3. the standard deviation of \italic{y}\italic{\subscript{i}} about the mean line is constant, independent of \italic{x}, and
	4. there is no error in the values of the independent variable, \italic{x}\italic{\subscript{i}}.
\flushleft{
\\
do 	nextscr
jump	pg4

unit 	pg4
next 	sample3
back	pg3
text
}The \italic{confidence limits for the slope of the population} have the form:\tim{
\\
font	zsans,20
calc	i:=zwherey+40}
at	15,i
text 	
confidence limit
for population slope\tim{
}\flushleft{\tim{\\
at	zwherex,i+10
write	  = }}\flushleft{sample slope  }\flushleft{\tim{+}}\flushleft{/-  
at	zwherex,i
text
half the confidence
interval (}\italic{\flushleft{c%}}\flushleft{)
\\
font
at	0,zwherey+40
text
}The \italic{confidence coefficient} \italic{c} is defined such that for repeated sampling from the population, and construction from each sample of the \italic{c%} confidence limits for some population characteristic, \italic{c%} of the time the population characteristic will lie within those limits.\tim{
\\
}\flushleft{\tim{do	nextscr
jump	sample3

unit	pg4half
next	sample2
back	sample3
text
}}\flushleft{The }\italic{\flushleft{confidence limits for the mean of the population at any x}}\flushleft{ have a similar form, but change with x:}\flushleft{\tim{
\\
font	zsans,20
calc	i:=zwherey+40
at	15,i
text
confidence limits 
\\
at	zwherex,i+10
write	= 
at	zwherex,i
write	 least squares
	mean value at }}\italic{\flushleft{\tim{x
}}}at	zwherex,i+10
\flushleft{write	 }\flushleft{\tim{+/- half the confidence interval at }}\italic{\flushleft{\tim{x}}}\flushleft{\tim{ (}}\italic{\flushleft{\tim{c}}}\flushleft{\tim{%)
at	0,i+20
write	         for mean
font
at	0,zwherey+40
text
}}This equation gives a pair of curves, the (\italic{c%}) confidence limits, useful in judging where the mean of the population at any \italic{x} may lie.\tim{
}\flushleft{\tim{\\
}}\flushleft{at	205,187
write	}\flushleft{\tim{
do	nextscr
jump	sample2

unit	pg5
next	pg6
back	sample2
text
}}Again, the meaning of the confidence coefficient of 95%, is that 95% of the times a sample is drawn and confidence limits are constructed, these limits \italic{do} include the mean population at that \italic{x}, and 5% of the time they do not.
\\\tim{
}\flushleft{\tim{do 	nextscr
jump	pg6

unit	pg6
next	sample4
back	pg5
text
}}\italic{Prediction limits for one more observation} can also be constructed.  For a prediction coefficient \italic{c%} and a specific location \italic{x}, the prediction limits provide an interval in \italic{y}.  \italic{c%} of the times a sample is drawn and one more data point is observed at that location \italic{x}, the point will lie within the prediction interval; (100 - \italic{c})\italic{%} of the time, it will lie outside of the interval.  the prediction interval for more observation is greater than the corresponding confidence interval because not only is the population mean unknown, but also the \italic{y} value of the single sample.\tim{
}\flushleft{\tim{\\
do 	nextscr
jump 	sample4

unit	pg7
next	userchoose
back	sample4
text
}}Confidence limits are useful in determining the relationship of certain characteristics to others for very large amounts of data.  The prediction limits are important in cases where one experiment or one device is to be produced, and an appropriate range of its characteristics \italic{must} be known.
\\\tim{
}\flushleft{\tim{do 	nextscr
jump	userchoose

unit	bib
next	userchoose
back 	pg7
text
}}Further Reading:

	McClintock, Frank A., Statistical Estimation: Linear Regression and Single Variable, Research Memo 274 (1989).
	McClintock, Frank A., \italic{Small Sample Statistics}, 2.671 Course Notes (1972).
	Dixon, W. J. and F. J. Massey, Jr.: "Introduction to Statistical Analysis," McGraw-Hill Book Company, Inc.  New York 1951.
\\\tim{
}\flushleft{\tim{do	nextscr
jump	userchoose

unit	programcode
}}\tim{text
}Program code information:


\\\tim{
}\flushleft{\tim{font	zsans,15
text}}\flushleft{\helv{
a = true intercept = 3					Sx =  Sx	
b = true slope = .7						Sy = Sy
n  = number of sampled points  = 25				Sxy =  Sx*y
sig  = standard deviation of sampled points  =1		Sx2 = Sx}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{
studT = t distribution value (95%)  = 1.71
a1 = least squares intercept  = (Sx2 * Sy - Sx * Sxy)/(n * Sx2 - (Sx)}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{)
b1 = least squares slope  = (n * Sxy - Sy * Sx)/(n *  Sx2 - (Sx)}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{)
xave = average x = Sx/n
yave =  average y  = Sy/n
sdx  = standard deviation of x about their mean = [1/(n - 1) * S(x0 - xave)}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{]}}\superscript{\flushleft{\helv{.5}}}\flushleft{\helv{, 0 < x0 < 8
sdyx =  standard deviation of y-data about least squares line
      = \{1/(n - 2) * S[y0 - (a1 + b1  * x0)]}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{\}}}\superscript{\flushleft{\helv{.5}}}\flushleft{\helv{, y0 = a1 + b1 * x0, 0 < x0 < 8
b = confidence limits for slope = b1 +/- studT * sdyx/sdx * (n-1)}}\superscript{\flushleft{\helv{-.5
}}}\flushleft{\helv{m}}\subscript{\flushleft{\helv{y}}}\flushleft{\helv{(x) = confidence limits for mean
     = yave + b1 * (x0 - xave) +/- studT * sdyx * \{1/n + (x0 - xave)}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{/[(n - 1) * xave}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{]\}}}\superscript{\flushleft{\helv{.5}}}\flushleft{\helv{
y}}\subscript{\flushleft{\helv{n+1}}}\flushleft{\helv{ = prediction limits  for one more observation
     = yave + b1 * (x0 - xave) +/- studT * sdyx * \{1 + 1/n + (x0 - xave)}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{/[(n - 1) * xave}}\superscript{\flushleft{\helv{2}}}\flushleft{\helv{]\}}}\superscript{\flushleft{\helv{.5


\\}}}\superscript{\flushleft{\tim{
}}}font
do	nextscr2
jump	userchoose

unit	nextscr2
box	25,375;475,396;3
text	1,372
\center{Click to return to supplemental information page
}\\
loop
	pause	keys=touch
\flushleft{	}\flushleft{\tim{if	(ztouchx>24)&(ztouchx<476)&(ztouchy>374)&(ztouchy<397)
		outloop
	endif
endloop
mode	xor
box	25,375;475,396;-12
pause	1
erase
mode	write}}\superscript{\flushleft{\tim{
}}}\flushleft{\tim{
unit 	nextscr
box 	125,375;375,396;3
text	1,373
}}\center{Click here to continue}\center{\tim{
}}\flushleft{\tim{\\
loop
	pause	keys=touch
	if	(ztouchx>124)&(ztouchx<376)&(ztouchy>374)&(ztouchy<397)
		outloop
	endif
endloop
mode	xor
box	125,375;375,396;-12
pause	1
erase
mode	write

unit 	pre0
jump	cover
unit 	pre2
jump	pg2
unit	pre3
jump	pg3
unit	pre4
jump	pg4
unit	pre4half
jump	pg4half
unit 	pre5
jump	pg5
unit	pre6
jump	pg6
unit	pre7
jump	pg7
unit	pre8
jump	userchoose
unit	pre2a
jump	sample
unit	pre4aa
jump	sample3
unit	pre4a
jump	sample2
unit	pre6a
jump	sample4

unit	graph
gorigin	225,250		$$set up and dimension graph
axes	265,240
scalex	8
scaley	11
labelx	1,.5
labely	1,.5
at	468,275		$$label axes
}}\tim{write	}x\tim{
}\flushleft{\tim{at	185,12
}}\tim{write	}y\tim{
}\flushleft{\tim{
unit	points
at	15,0
}}\tim{write	}x\tim{
}\flushleft{\tim{at	55,0
}}\tim{write 	}y\subscript{i}\tim{
}\flushleft{\tim{calc	a:=3		$$a=y-intercept of line
	b:=.7		$$b=slope of line
	sig:=1		$$std dev of sampled points
calc	st  :=8/n		$$st=step between sampled points}}\superscript{\flushleft{\tim{
do	pickpoints
font	zsans,20
}}}\flushleft{\tim{loop	i  :=1,n
	at	0,i*13+10			$$show point and coordinates of point
	show	st*i,3
	at	50,i*13+10
	show	s(i),3
	gat	st*i,s(i)
	gcircle	.05
endloop
font

unit	pickpoints
calc	Sx:=0		$$Sx=}}\flushleft{\symb{S}}\flushleft{\tim{x
	Sy:=0		$$Sy=}}\flushleft{\symb{S}}\flushleft{\tim{y
	Sxy:=0		$$Sxy=}}\flushleft{\symb{S}}\flushleft{\tim{x*y
	Sx2:=0		$$Sx2=}}\flushleft{\symb{S}}\flushleft{\tim{x}}\superscript{\flushleft{\tim{2}}}\flushleft{\tim{
loop	i:=1,n	$$seect n random points
	do	random
	calc	s(i):=k1+b*st*i+a
		Sy  :=Sy+s(i)			$$sum up points
		Sx  :=Sx+st*i
		Sx2  :=Sx2+(st*i)^2
		Sxy :=Sxy+s(i)*st*i
endloop

unit	random
randu	k,1000
calc	k:=k/1000
if	k<=.0797
	calc	k1:=.1*sig
elseif	k<=.1585
	calc	k1:=.2*sig
elseif	k<=.2358
	calc	k1:=.3*sig
elseif	k<=.3108
	calc	k1:=.4*sig
elseif	k<=.3829
	calc	k1:=.5*sig
elseif	k<=.4515
	calc	k1:=.6*sig
elseif	k<=.5161
	calc	k1:=.7*sig
elseif	k<=.5763
	calc	k1:=.8*sig
elseif	k<=.6319
	calc	k1:=.9*sig
elseif	k<=.6827
	calc	k1:=sig

elseif	k<=.7287
	calc	k1:=1.1*sig
elseif	k<=.7699
	calc	k1:=1.2*sig
elseif	k<=.8064
	calc	k1:=1.3*sig
elseif	k<=.8385
	calc	k1:=1.4*sig
elseif	k<=.8664
	calc	k1:=1.5*sig
elseif	k<=.8904
	calc	k1:=1.6*sig
elseif	k<=.9109
	calc	k1:=1.7*sig
elseif	k<=.9281
	calc	k1:=1.8*sig
elseif	k<=.9426
	calc	k1:=1.9*sig
elseif	k<=.9545
	calc	k1:=2*sig

elseif	k<=.9643
	calc	k1:=2.1*sig
elseif	k<=.9722
	calc	k1:=2.2*sig
elseif	k<=.9786
	calc	k1:=2.3*sig
elseif	k<=.9836
	calc	k1:=2.4*sig
elseif	k<=.9876
	calc	k1:=2.5*sig
elseif	k<=.9907
	calc	k1:=2.6*sig
elseif	k<=.9931
	calc	k1:=2.7*sig
elseif	k<=.9949
	calc	k1:=2.8*sig
elseif	k<=.9963
	calc	k1:=2.9*sig
elseif	k<=.9973
	calc	k1:=3*sig
	
else
	calc	k1:=3.5*sig
endif
randu	k,2
calc	k1:=k1*(-1)^k

unit	berase
erase	0,300;500,400

unit	average
calc	xave:=Sx/n
	yave:=Sy/n
calc 	a1  :=(Sx2*Sy-Sx*Sxy)/(n*Sx2-Sx^2)
calc	b1  :=(n*Sxy-Sy*Sx)/(n*Sx2-Sx^2)
	em:=abs(m-b1)			$$calculate errors
	eb:=abs(int-a1)
loop	i:=1,n
	calc	sdx:=sdx+(st*i-xave)^2
		sdyx:=sdyx+(s(i)-(a1+b1*st*i))^2
endloop
calc	sdx:=(sdx/(n-1))^.5
	sdyx:=(sdyx/(n-2))^.5

unit	drawline
loop
	if	flag2=0
		erase	100,300;500,400
		at	100,300
}}\tim{		write	}Hold the mouse button down and drag a line you think is the least squares fit.
	elseif	flag2=2
		erase	100,300;500,400
		at	100,300
		write	Try again.\tim{
}\flushleft{\tim{	endif
	loop
		pause	keys=touch
		if	(zgtouchx>0)&(zgtouchx<8)&(zgtouchy>0)&(zgtouchy<11)
			outloop
		endif
	endloop
	calc	x1:=lastx:=zgtouchx
		y1:=lasty:=zgtouchy
	gdot	x1,y1
	mode	xor
	loop
		pause	keys=touch(left:move, up)
		outloop	zkey=zk(left:up)
		if	(zgtouchx>0)&(zgtouchx<8)&(zgtouchy>0)&(zgtouchy<11)
			gdraw	x1,y1;lastx,lasty
			gdraw	x1,y1;zgtouchx,zgtouchy
			calc	lastx:=zgtouchx
				lasty:=zgtouchy
		endif
	endloop
*analyze line drawn
	if	x1=lastx
		gdraw 	x1,y1;lastx,lasty
		gdot	x1,x1
		calc	flag2:=1
		erase	100,300;500,400
		if	y1=lasty
			at	100,300
}}\tim{			write	}Please draw a line.\tim{
}\flushleft{\tim{		else
			at	100,300
}}\tim{			write	}Please draw a nonvertical line.\tim{
}\flushleft{\tim{		endif
	else
		outloop
	endif
endloop	

unit	sample	$$ex of least squares fit
next	pg3
back	pg2
do	graph
calc	flag2:=0
text	0,300
}}In the following few screens, you will see an example of the application of the least squares fit.  Click the mouse button to see a sample of points.
\\\tim{
}\flushleft{\tim{pause	keys=all,touch
do	berase
}}\subscript{\flushleft{\tim{do	points}}}\flushleft{\tim{
loop
	do	drawline
	erase	100,300;500,400
	text	100,300
}}Are you satisfied with your line?\tim{
}\flushleft{\tim{\\
	box	180,375;220,396;3
	at	185,371
}}\tim{	write	}yes\tim{
}\flushleft{\tim{	box	250,375;290,396;3
	at	258,371
}}\tim{	write 	}no\tim{
}\flushleft{\tim{	loop
		calc	flag:=0
		pause	keys=touch
		if	(ztouchx>179)&(ztouchx<221)&(ztouchy>374)&(ztouchy<397)
			calc	flag:=1
			box	180,375;220,396;-16
			pause	1
			outloop
		elseif	(ztouchx>249)&(ztouchx<291)&(ztouchy>374)&(ztouchy<397)
			box	250,375;290,396;-16
			pause	1
			outloop
		endif
	endloop
	if	flag=1
		outloop
	else
		gdraw	x1,y1;lastx,lasty
		gdot	x1,y1
	endif
	calc	flag2:=2
endloop
calc	m:=(y1-lasty)/(x1-lastx)	$$slope?
	int:=y1-m*x1	$$intercept?
erase	100,300;500,400
text	100,300
}}Now watch as the computer plots the actual least squares fit.\tim{
}\flushleft{\tim{\\
pause	2
do	average
loop	x0:=0,8,.1
	gdot	x0,a1+x0*b1
endloop
do	berase
erase	0,0;150,400
font	zsans,20
at	0,0
}}write	Your slope: <|showt,m,2,2|>
	Actual slope: <|showt,b1,2,2|>
	Slope error: <|showt,em,2,2|>

	Your y-intercept: <|showt,int,2,2|>
	Actual y-intercept: <|showt,a1,2,2|>
	y-intercept error: <|showt,eb,2,2|>

	Actual equation:
	   y = <|showt,a1,2,2|> + <|showt,b1,2,2|> * x

	Your equation:
	  y = <|showt,int,2,2|> + <|showt,m,2,2|> * x
font
at	20,255
if	(em<.1)&(eb<.1)
	write	FANTASTIC!
elseif	(em<.3)&(eb<.3)
	write	GREAT!
elseif	(em<.5)&(eb<.5)
	write	GOOD!
elseif	(em<.7)&(eb<.7)
	write	NOT BAD!
elseif	(em<1)&(eb<1)
	write	OKAY!
elseif	(em<1.5)&(eb<1.5)
	write 	PRETTY GOOD!
else
	write	OOPS!
endif
text	0,300
The dashed line is the least squares fit.  On the left side of the screen, you can compare your line to the least squares fit of this sample.  Please click to continue.
\\\tim{
}\flushleft{\tim{pause	keys=touch
pause	1
jump	pg3

unit	sample2	$$NEW example of confidence limits for the mean of the population
next	pg5
back	pg4half
mode	xor
do	graph
text	0,300
}}In the following few screens, you will see an example of confidence limits for the mean of the population.  Click to see a sample of points.
\\\tim{
}\flushleft{\tim{pause	keys=touch
do	berase
do	points
do	exprelim
do	berase
at	0,300
}}\tim{write	}Now click to see if the <|s,cc|>% confidence limits include the true mean at \italic{x} = <|s,xcalc|>.\tim{
}\flushleft{\tim{pause	keys=touch
loop	x0:=0,30,3
	dot	x0,180
endloop
font	zsans,20
at	35,170
}}\tim{write	}confidence limits\tim{
}\flushleft{\tim{font
calc	flag:=0
loop	x0:=0,8,.1
	calc	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
		clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	gdot	x0,clmp
	gdot	x0,clmp1
endloop
calc	x0:=xcalc
	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
if	(clmp<a+b*x0)|(clmp1>a+b*x0)
	calc	flag:=1
endif
gvector	xcalc,.5;xcalc,a+b*xcalc-2;7
gvector	xcalc,11;xcalc,a+b*xcalc+2;7
do	berase
at	0,300
if	flag=1
}}\tim{	}write	The confidence limits do not include the true mean at \italic{x}  = <|s,xcalc|>!
else
	write	The confidence limits do include the true mean at \italic{x}  =  <|s,xcalc|>!
endif\tim{
}\flushleft{\tim{pause	2
at	0,350
}}\tim{write	}Please click to continue.\tim{
}\flushleft{\tim{pause	keys=all,touch
erase	0,0;150,400
do	berase
text	0,300
}}Now we will test the confidence limits of other samples.  Click to indicate how many samples you wish to see.
\\\tim{
}\flushleft{\tim{do	boxes
loop	l:=1,j
	do	sample2more
	if 	flag=1
		calc	sf(1):=sf(1)+1
	else
		calc	sf(2):=sf(2)+1
	endif
	erase	110,0;150,70
	at	110,0
	show	sf(2)
	at	110,40
	show	sf(1)
endloop
calc	sf(3):=100*sf(2)/(sf(1)+sf(2))
do	berase
at	0,300
}}\tim{write	}For these samplings, there were <|s,sf(2)|> successes and <|s,sf(1)|> failures for a success rate of <|s,sf(3)|>%.\tim{
}\flushleft{\tim{pause	1
do	nextscr
jump	pg5

unit	sample2more
loop	i:=1,n
	gat	st*i,s(i)
	gcircle	.05
endloop
loop	x0:=0,8,.1
	calc	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
		clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	gdot	x0,clmp
	gdot	x0,clmp1
endloop
do	pickpoints
loop	i:=1,n
	gat	st*i,s(i)
	gcircle	.05
endloop
do	average
calc	flag:=0
loop	x0:=0,8,.1
	calc	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
		clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	gdot	x0,clmp
	gdot	x0,clmp1
endloop
calc	x0:=xcalc
	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
if	(clmp<a+b*x0)|(clmp1>a+b*x0)
	calc	flag:=1
endif
pause	.5

unit	sample3more
loop	i:=1,n
	gat	st*i,s(i)
	gcircle	.05
endloop
loop	x0:=0,8,.1
	gdot	x0,clmp*x0+a
	gdot	x0,clmp1*x0+a
endloop
do	pickpoints
loop	i:=1,n
	gat	st*i,s(i)
	gcircle	.05
endloop
do	average
calc	flag:=0
calc	clmp:=b1+studT*sdyx/sdx*(n-1)^-.5
	clmp1:=b1-studT*sdyx/sdx*(n-1)^-.5
loop	x0:=0,8,.1
	gdot	x0,clmp*x0+a
	gdot	x0,clmp1*x0+a
endloop
if	(clmp<b)|(clmp1>b)
	calc	flag:=1
endif
pause	.5

unit	boxes
mode	xor
box	100,375;140,396;3
box	150,375;190,396;3
box	200,375;240,396;3
box	250,375;290,396;3
box	300,375;340,396;3
at	115,373
}}\tim{write	}1\tim{
}\flushleft{\tim{at	158,373
}}\tim{write	}10\tim{
}\flushleft{\tim{at	208,373
}}\tim{write	}25\tim{
}\flushleft{\tim{at	258,373
}}\tim{write	}50\tim{
}\flushleft{\tim{at	304,373
}}\tim{write	}100\tim{
}\flushleft{\tim{loop
	pause	keys=touch
	if	(ztouchx>99)&(ztouchx<141)&(ztouchy>374)&(ztouchy<397)
		box	100,375;140,396;-16
		calc	j:=1
		outloop
	elseif	(ztouchx>149)&(ztouchx<191)&(ztouchy>374)&(ztouchy<397)
		box	150,375;190,396;-16
		calc	j:=10
		outloop
	elseif	(ztouchx>199)&(ztouchx<241)&(ztouchy>374)&(ztouchy<397)
		box	200,375;240,396;-16
		calc	j:=25
		outloop
	elseif	(ztouchx>249)&(ztouchx<291)&(ztouchy>374)&(ztouchy<397)
		box	250,375;290,396;-16
		calc	j:=50
		outloop
	elseif	(ztouchx>299)&(ztouchx<341)&(ztouchy>374)&(ztouchy<397)
		box	300,375;340,396;-16
		calc	j:=100
		outloop
	endif
endloop
loop	x0:=0,8,.3
	gdraw	x0,a1+x0*b1;x0+.2,a1+(x0+.2)*b1
endloop
do	berase
erase	0,0;150,400
at	0,0
}}\tim{write	}Successes:\tim{
}\flushleft{\tim{at	0,40
}}\tim{write	}Failures:\tim{
}\flushleft{\tim{calc	sf(1):=sf(2):=0
}}\tim{at	0,300}
write	Watch at the top left as the number of successes and failures is recorded.\tim{
}\flushleft{\tim{pause	2

unit	sample4	$$NEW example of prediction  limits
next	pg7
back	pg6
mode	xor
do	graph
text	0,300
}}In the following few screens, you will see an example of prediction limits for one more observation.  Click to see a sample of points.
\\\tim{
}\flushleft{\tim{pause	keys=all,touch
do	berase
do	points
do	exprelim
do	berase
at	0,300
}}\tim{write	}Now click to see the <|s,cc|>% prediction limits for one more observation.\tim{
}\flushleft{\tim{pause	keys=all,touch
loop	x0:=0,30,3
	dot	x0,180
endloop
font	zsans,20
at	35,170
}}\tim{write	}prediction limits\tim{
}\flushleft{\tim{font
calc	studT:=1.71
	flag:=0
loop	x0:=0,8,.1
	calc	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1+1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
		clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1+1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	gdot	x0,clmp
	gdot	x0,clmp1
endloop
pause	1
do	berase
erase	0,0;150,400
text	0,300
}}Now we will test the prediction limits by sampling points at \italic{x} = <|s,xcalc|>.  Click to indicate how many samples you wish to see.
\\\tim{
}\flushleft{\tim{do	boxes
loop	i:=1,n
	gat	st*i,s(i)
	gcircle	.05
endloop
calc	x0:=xcalc
	clmp:=yave+b1*(x0-xave)+studT*sdyx*(1+1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
	clmp1:=yave+b1*(x0-xave)-studT*sdyx*(1+1/n+(x0-xave)^2/((n-1)*sdx^2))^.5
loop	l:=1,j
	do	random
	calc	s(1):=k1+b*xcalc+a
	gat	xcalc,s(1)
	gcircle	.05
	do	average
	calc	flag:=0
	if	(clmp<s(1))|(clmp1>s(1))
		calc	flag:=1
	endif
	if 	flag=1
		calc	sf(1):=sf(1)+1
	else
		calc	sf(2):=sf(2)+1
	endif
	erase	110,0;150,70
	at	110,0
	show	sf(2)
	at	110,40
	show	sf(1)
	pause	1
	gat	xcalc,s(1)
	gcircle	.05
endloop
calc	sf(3):=100*sf(2)/(sf(1)+sf(2))
do	berase
at	0,300
}}\tim{write	}For these samplings, there were <|s,sf(2)|> successes and <|s,sf(1)|> failures for a success rate of <|s,sf(3)|>%.\tim{
}\flushleft{\tim{pause	1
do	nextscr
jump	pg7

unit	exprelim
at	100,300
}}\tim{write	}Now click to see the true mean line.\tim{
}\flushleft{\tim{pause	keys=all,touch
pause	.5
erase	0,0;150,400
do	average
gdraw	0,a;8,a+8*b
gdraw	0,a-.03;8,a+8*b-.05
box	0,100;30,102
font	zsans,20
at	35,90
}}\tim{write	}true mean line\tim{
}\flushleft{\tim{font
do	berase
at	0,300
}}\tim{write	}Click again to see the least squares fit.\tim{
}\flushleft{\tim{pause	keys=all,touch
pause	.5
loop	x0:=0,8,.3
	gdraw	x0,a1+x0*b1;x0+.2,a1+(x0+.2)*b1
endloop
loop	x0:=0,30,11
	draw	x0,140;x0+8,140
endloop
font	zsans,20
at	35,130
}}\tim{write	}least squares fit\tim{
}\flushleft{\tim{font

unit	userchoose
back	bib
mode	xor
text
}}\tim{	}Now that you have seen the material once, you may wish to reduce the number of sample points so that you can observe a large number of samples in a shorter time.  In addition, you may wish to select a different x value for x at which to test condfidence and prediction limits.  To change these parameters, click in the box marked parameters.
	If you are interested in changing this module's program code, click in the program code box to see information on the formulas used to compute the least squares fit, confidence limits, and prediction limits and information on variables used in the program.
	If you would like to run the module again, click in the restart box.\tim{
}\flushleft{\tim{\\
*	boxes!!!
loop	i:=0,3
	box	3+125*i,375;125*(i+1)-6,396;3
endloop
at	8,372
}}\tim{write	}Parameters\tim{
}\flushleft{\tim{at	147,372
}}\tim{write	}Program\tim{
}\flushleft{\tim{at	275,372
}}\tim{write	}Restart\tim{
}\flushleft{\tim{at	415,372
}}\tim{write	}Quit
loop
	pause	keys=touch
	if	(ztouchy>374)&(ztouchy<397)\tim{
}\flushleft{\tim{		if	(ztouchx>2)&(ztouchx<120)
			box	3,375;119,396;-16
			pause	1
			jump	parameters
		elseif	(ztouchx>127)&(ztouchx<245)
			box	128,375;244,396;-16
			pause	1
			jump	programcode
		elseif	(ztouchx>252)&(ztouchx<370)
			box	253,375;369,396;-16
			pause	1
			jump	cover
		elseif	(ztouchx>377)&(ztouchx<495)
			box	378,375;494,396;-16
			pause	1
			jump	quit
		endif
	endif
endloop

unit	quit

unit	parameters
mode	xor
write	To change a parameter, click in the appropriate box.
loop	i:=1,4
	loop	j:=0,1
		box	i*60+160,j*30+75;i*60+210,j*30+96;3
	endloop
	loop	j:=5,6
		box	i*60+160,j*30+75;i*60+210,j*30+96;3
	endloop
endloop
at	0,85
write	Number of sample points
at	0,235
write	Test point for limits
at	240,73
write	3
at	300,73
write	5
at	360,73
write	7
at	415,73
write	10
at	235,103
write	15
at	295,103
write	25
at	355,103
write	50
at	410,103
write	100
loop	i:=1,4
	at	i*60+163,223
	write	x = <|s,i|>
	at	i*60+163,253
	write	x = <|s,i+4|>
endloop
}}\tim{box	25,375;475,396;3
text	1,372
}\center{\tim{Click to return to supplemental information page
}}\tim{\\
}\flushleft{\tim{loop
	erase	220,135;500,160
	erase	220,285;500,310
	at	220,135
	write	Current setting: n = <|s,n|>
	at	220,285
	write	Current setting: x = <|s,xcalc|>
	calc	flag:=0
	loop
		pause	keys=touch
		if	(ztouchy>74)&(ztouchy<97)
			if	(ztouchx>219)&(ztouchx<271)
				calc	n:=3
				outloop
			elseif	(ztouchx>279)&(ztouchx<331)
				calc	n:=5
				outloop
			elseif	(ztouchx>339)&(ztouchx<391)
				calc	n:=7
				outloop
			elseif	(ztouchx>399)&(ztouchx<451)	
				calc	n:=10
				outloop
			endif
		elseif	(ztouchy>104)&(ztouchy<127)
			if	(ztouchx>219)&(ztouchx<271)
				calc	n:=15
				outloop
			elseif	(ztouchx>279)&(ztouchx<331)
				calc	n:=25
				outloop
			elseif	(ztouchx>339)&(ztouchx<391)
				calc	n:=50
				outloop
			elseif	(ztouchx>399)&(ztouchx<451)	
				calc	n:=100
				outloop
			endif		
		elseif	(ztouchy>224)&(ztouchy<247)
			if	(ztouchx>219)&(ztouchx<271)
				calc	xcalc:=1
				outloop
			elseif	(ztouchx>279)&(ztouchx<331)
				calc	xcalc:=2
				outloop
			elseif	(ztouchx>339)&(ztouchx<391)
				calc	xcalc:=3
				outloop
			elseif	(ztouchx>399)&(ztouchx<451)	
				calc	xcalc:=4
				outloop
			endif
		elseif	(ztouchy>254)&(ztouchy<277)
			if	(ztouchx>219)&(ztouchx<271)
				calc	xcalc:=5
				outloop
			elseif	(ztouchx>279)&(ztouchx<331)
				calc	xcalc:=6
				outloop
			elseif	(ztouchx>339)&(ztouchx<391)
				calc	xcalc:=7
				outloop
			elseif	(ztouchx>399)&(ztouchx<451)	
				calc	xcalc:=8
				outloop
			endif
		elseif	(ztouchx>24)&(ztouchx<476)&(ztouchy>374)&(ztouchy<397)
			calc	flag:=1
			outloop
		endif
	endloop
	if	flag=1
		outloop
	endif
endloop
box	25,375;475,396;-12
pause	1
jump	userchoose

unit	sample3	$$NEW example of confidence limits for the slope of the population
next	pg4half
back	pg4
mode	xor
do	graph
text	0,300
}}In the following few screens, you will see an example of confidence limits for the slope of the regression line of the population.  Click to see a sample of points.
\\\tim{
}\flushleft{\tim{pause	keys=touch
do	berase
do	points
do	exprelim
do	berase
at	0,300
}}\tim{write	}Now click to see if the <|s,cc|>% confidence limits for the slope include the slope of the true mean.\tim{
}\flushleft{\tim{pause	keys=touch
loop	x0:=0,30,3
	dot	x0,180
endloop
font	zsans,20
at	35,170
}}\tim{write	}confidence limits\tim{
}\flushleft{\tim{font
calc	flag:=0
calc	clmp:=b1+studT*sdyx/sdx*(n-1)^-.5
	clmp1:=b1-studT*sdyx/sdx*(n-1)^-.5
loop	x0:=0,8,.1
	gdot	x0,clmp*x0+a
	gdot	x0,clmp1*x0+a
endloop
if	(clmp<b)|(clmp1>b)
	calc	flag:=1
endif
do	berase
at	0,300
if	flag=1
}}\tim{	}write	The confidence limits do not include the true slope!
else
	write	The confidence limits do include the true slope!
endif\tim{
}\flushleft{\tim{pause	2
at	0,350
}}\tim{write	}Please click to continue.\tim{
}\flushleft{\tim{pause	keys=all,touch
erase	0,0;150,400
do	berase
text	0,300
}}Now we will test the confidence limits for slopes of other samples.  Click to indicate how many samples you wish to see.
\\\tim{
}\flushleft{\tim{do	boxes
loop	l:=1,j
	do	sample3more
	if 	flag=1
		calc	sf(1):=sf(1)+1
	else
		calc	sf(2):=sf(2)+1
	endif
	erase	110,0;150,70
	at	110,0
	show	sf(2)
	at	110,40
	show	sf(1)
endloop
calc	sf(3):=100*sf(2)/(sf(1)+sf(2))
do	berase
at	0,300
}}\tim{write	}For these samplings, there were <|s,sf(2)|> successes and <|s,sf(1)|> failures for a success rate of <|s,sf(3)|>%.\tim{
}\flushleft{\tim{pause	1
do	nextscr
jump	pg4half
}}\enddata{text,204354}
