Empirical Models

advertisement
Technology for Chapter 4: Empirical Modeling in Maple
We will use the following to illustrate the use of technology.
1. PURPOSE: To provide the student the opportunity to develop and use Empirical
modeling techniques using technology.
2. OBJECTIVE: Determine if the hearts of mammals are geometrically similar using
your knowledge of proportionality models and technology. Provide a summary of your
analysis using the following data to support or refute your argument.
Animal
Heart Weight
(in grams)
Mouse
Rat
Rabbit
Dog
Sheep
Ox
Horse
0.13
0.64
5.80
102.00
210.00
2030.00
3900.00
Length of cavity of
left ventricle (in)
0.55
1.00
2.20
4.00
6.50
12.00
16.00
3. PROCEDURE:
a. Obtain a scatter plot and note the trends.
b. Use ladder of powers to try to obtain a model (see ladder of powers steps below),
Use Divided Difference table to obtain a low order polynomial (see Divided
Difference steps below), or Use Cubic Splines (see Cubic Splines information
below)
Ladder of Powers
Step 1. If trend of data allows for use of Ladder of Powers begin using a transformation
by the ladder on only one variable. Obtain a plot of the transformed data and continue
until you have the most linear plot.
Step 2. Use least squares to fit the parameters of the model as per Chapter 3 technology.
Step 3. Interpret results
Divided Difference
Step 1. Put the ordered data into the divided difference table and interpret,
Step 2. Fit the complete low order polynomial suggested using the least squares
technology from Chapter 3 (but now use y=ax^2+bx+c form).
Step 3. Interpret Results
Cubic Splines
Step 1. Put the ordered data into the spline library
Step 2. Interpret Results.
Example using Maple Template
Empirical Models for Lab
>
>
>
>
>
>
>
> #Interpret your scatterplot: Increasing and curved
upsilon
>
>
Basic Steps
Step 1. Plot the raw data and describe trends
Step 2, Identify any potential outliers. Resolve if possible.
Step 3. Choose one or more empirical technique(s) to try
Build a simple 1 term model. Use Least squares to
fit. Analyzie residuals for model adequacy.
Build a model from another transformation, such as
ln-ln model
Build a higher order (n-1) polynomial. Analyze
model for possible snaking and oscilations.
Use Divided Difference Table to qualitatively
access information about low order polyomials for your
data. Fit data with a low
order polynomial using least squares and
analyze residuals.
Use Cubic Splines if your have precise data and
need a perfect fit.
Empirical Models
Empirical Modeling
>
Simple One Term Models
> restart;
> Xdata := [.55, 1, 2.2, 4, 6.5, 12, 16]:
> Ydata := [.13, .64, 5.8, 102, 210, 2030, 3900]:
> XY:=array(1..2,1..7,[Xdata,Ydata]);
>
> with(plots):
>
pointplot({seq([Xdata[i],Ydata[i]],i=1..7)},style=point,sym
bol=box,view=[0..20,0..4000], title=`Scatterplot`);
Note: this looks like a function that is
concave up and increasing. The ladder of
powers (for tranforming x) would make x^2,
x^3, etc. If we were to tranform y then we
would try sqrt(y), log(y), -1/sqrt(y),-1/y, etc.
We do this graphically trying to obtain a
"straight line".
> tran2:=map(x->x^2,Xdata):
> tran2XY:=array(1..2,1..7,[X^2,Ydata]);
> tran3:=map(x->x^3,Xdata):
> tran3xy:=array(1..2,1..7,[x^3,Ydata]);
> pointplot({seq([tran2[i],Ydata[i]],i=1..7)},
style=point,symbol=box,title=`y versus x^2`);
> pointplot({seq([tran3[i],Ydata[i]],i=1..7)},
style=point,symbol=box, title=`y versus x^3`);
>
>
>
>
>
>
The cubic model does better if this example.
> #Fit with least Squares and Analyze the adequacy of the
model.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> eq_fit:= fit[leastsquare[[x,y], y=a*x^3, {a}]]([xobs,
yobs]);
>
Transform this into a procedure
> eq_function:=unapply(rhs(eq_fit),x);
Then give the predicted values (we could have used map() in this case, since the data
does not involve classes or weights)
> Yvaluespredicted:=transform[apply[eq_function]](xobs);
Find the residuals:
> Residuals:=transform[multiapply[(x,y)-> x-y]]([yobs,
Yvaluespredicted]);
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> eq_fit:= fit[leastsquare[[x,y], y=a*x+b, {a,b}]]([lnX,
lnY]);
>
>
>
>
>
>
>
>
>
>
>
Divided Difference Tables
>
> ddproc:=proc(x,y) local len,xym,j,k;
> len:=describe[count](y):
> xym:=matrix(len,len):
> for j from 1 to len do for k from 1 to len do
xym[j,k]:=0:od:od:
> for j from 1 to len do xym[j,1]:=x[j]:od:for j from 1 to
len do xym[j,2]:=y[j]:od:
> for j from 2 to (len-1) do for k from j to len do
> xym[k,j+1]:=(xym[k,j]-xym[k-1,j])/(xym[k,1]-xym[k-(j1),1]):
> if abs(xym[k,j+1])<10^(-5) then xym[k,j+1]:=0:fi:od:od:
> Digits:=4:
> return(evalf(evalm(xym)))
> end:
> with(stats):with(linalg):
>
> ddproc(xobs,yobs);
> # Interpret the DD table.
The negative value (-2.382) in the second DD column makes all further columns invalid.
Therefore, the DD table does not specifically led to a lower order polynomial to try.
>
>
Interpolating Polynomials
Interpolating Polynomials
Maple has instrinsic functions to call for
interploating polynomials.
Here are some examples.
>
>
>
> FI:=interp(xobs,yobs,z);
> convert(%,float);
>
> plot(-0.01564695895 *z^6+0.5804947800 *z^5-21.942918467.457535872* z^4+78.39266569* z+41.07995156* z^389.99701075* z^2,z=0..17);
>
>
>
>
>
>
Cubic Splines
>
This is our example and now we are fitting
with cubic splines.
>
>
>
>
>
>
>
>
readlib(spline):
spline(xobs,yobs,x,cubic):
s:=unapply(%,x):
with(plots):
dxy:=pointplot({seq([xobs[i],yobs[i]],i=1..7)}):
curve:=plot(s(x),x=0..17):
display({dxy,curve});
Download