CHAPTER 3
FITTING EQUATIONS

A study of the relationship between two or more variables, frequently, involves collecting sets of data on the variables and finding how changes in one variable affects the values of the other variables.  An initial investigation of the relationship between variables is usually done by plotting the scatter diagrams of sets of data.  Although plotting scatter diagrams are highly recommended for initial investigation of the relationship between variables, they do not specify the form of the relationship between the variables and do not determine the strength of the relationship between the variables statistically.  By finding the best fitting line or curve to sets of data, the relationship between the variables can be expressed in mathematical form and the strength of the relationship between variables can be evaluated statistically. The process of fitting a line or a curve to sets of data is called regression.  
The most common procedure to fit a linear regression is the least-squares technique.  The least-squares technique and regression analysis integrate differential calculus and statistics and provide a means of model building, estimation, statistical analysis and forecasting. The detailed techniques of model building, fitting curves and statistical analysis will not be discussed in this book.  Here, we will briefly study the methods of fitting lines and curves using least-squares technique.  The interested reader is referred to any standard Statistics or Econometrics text book.   

TOOL BOX
Mathematica Commands			Function
data = {{1,3}, {4,7}, (5,3}, {9,4}}		Defines "data" as a list of 4 paired observations x, y.
N[Log[data]]					Transforms observations in "data" to natural log.
Fit[data, {1, x, x^2}, x]				Fits a best fitting parabola to pre-defined "data" table  
Show[plot1, plot2]				Shows plots called plot1 and plot2 together
ListPlot[data]					Listplots the table called "data"
ListPlot3D[data]				3D Plot of a 3-dimensional list of data called "data'
PlotStyle       					Sets plot options of color, thickness, and others 
InterpolatingPolynomial			Fits a polynomial of degree n - 1 to n observations

I.   Fitting  Lines:  The Fit & Show Commands
For  every two points on a coordinate system we can fit a line that contains the points.  Such a fit will be a perfect fit because the distances between the points and the fitted line, or the errors between the actual points and the fitted line, will be zero. In general, for every set of n data points we can fit a polynomial of order n -1 which passes through all the points.  However, fitting such polynomial will limit degrees of freedom for any statistical test and  will be of no practical value. In practice, the type of the function to be fitted to a set of data is decided by a  combination of eyeballing (observing the shape of the relationship through the list plot of data), statistical tests of best fit, and by implications of relevant economic theory. 
 
Example: Fit a line to points A(1, 3) and B(4, 2). 
Solution:  A line fitted to any two points is a perfect fit.  Find the slope (m) of the line as the ratio of the rise to run, m = ((2  -  3)/(4  -  1))= ((-1)/3).  Using y = mx + c, find the y-intercept as 3 = ((-1)/3) + c, or c = (10/3).  The equation of the line is y = ((-1)/3)x + (10/3).  The points and the graph of the line is shown below



However, if the number of points is more than two and if the points are not all lying on the same line, any fitted line will not contain all the points.  For every point, the distance between the fitted line and the point measures the error of the fit.  The graph below shows five points {{1, 3}, {4, 2}, {3, 3}, {3, 2.5}, {4, 2.2}} and the best line fitted to the points.  


 
The equation of the fitted line is y = 3.5 -. 33x.  For every value of x, the table below shows the actual values of y, the estimated values of the y, and the errors of estimation, which are equal to actual minus estimated ys.
({{x, 1, 4, 2, 3, 4}, {Actual y, 3, 2, 3, 2.5, 2.2}, {Estimated y, 3.17, 2.18, 2.84, 2.51, 2.18}, {Error, - .17, - .18, .16, - .01, .02}})
It is clear from the graph and the table that, if the fitted line is a good fit, the line will contain as many points or will pass through the points in such a way that the error distances from the estimated line will be minimum.  In statistics and econometrics, the least-squares technique is concerned with fitting a line or a curve to the points in such a way that the sum of the squares of the error distances between the actual points and the fitted line or curve is minimized.  
Let's assume a linear model,  (Subscript[Y, i]) = α + β(Subscript[X, i]) +  (Subscript[∈ , i]),  where α and β are intercept and slope coefficients, respectively, and ϵi is the distance between actual point i and the estimated line.  The least-squares technique estimates α and β in such a way that  ∑((Subscript[ϵ, i])^2) is minimized.  The least-square estimates of coefficients are \(TraditionalForm\`β\&^\) = \(TraditionalForm\`\(∑\+\(i = 1\)\%n\( x\_i\) y\_i\)\/\(∑\+\(i = 1\)\%n x\_i\^2\)\), where (Subscript[x, i]) and (Subscript[y, i]) are the deviations of (Subscript[X, i]) and (Subscript[Y, i]) from their corresponding means ((Subscript[x, i]) = (Subscript[X, i]) - \(TraditionalForm\`\(X\&-\)\) and (Subscript[y, i]) = (Subscript[Y, i]) - \(TraditionalForm\`\(Y\&-\)\)) and \(TraditionalForm\`α\&^\) = \(TraditionalForm\`\(Y\&-\)\) - \(TraditionalForm\`β\&^\)\(TraditionalForm\`X\&_\) .  The goodness of the fit is measured by multiple correlation coefficient (R2), which utilizes ∑((Subscript[ϵ, i])^2) to measure the portion of the variations in y that is explained by X.  That is, (R^2) = 1 - ((∑ϵ i 2)/(∑Y i 2)).  The closer (R^2) is to one, the better is the fit.  The statistical significance of the estimated α and β coefficients are measured by t statistics.  
In this chapter we will study the techniques of fitting lines and curves to data.  The statistical tests of goodness of the fit and significance of coefficients will not be discussed here.  The interested reader is referred to standard econometrics text books.

Example: Consumption Function and Marginal Propensity to Consume (MPC)
The following data represents annual disposable income and consumption of a country in millions of dollars. Fit the best fitting equation to data and estimate marginal propensity to consume.  
Income (Y):             2300, 2360, 2395, 2407, 2389, 2430, 2395, 2413, 2430, 2467, 2480, 2490            
Consumption (C):    2145, 2173, 2189, 2190, 2185, 2206, 2195, 2215, 2235, 2251, 2279, 2281
Solution:  In any consumption model, consumption depends on income.  Plot the data on the Y-C plane to study the functional form of the relationship between C and Y. 


The eyeballing of the plot clearly shows that the relationship between Y and C is more of a linear relation.  Therefore, we fit an equation of a line C = α + βY.  The least square estimate of β is \(TraditionalForm\`β\&^\) = \(TraditionalForm\`\(∑\+\(i = 1\)\%n\( c\_i\) y\_i\)\/\(∑\+\(i = 1\)\%n c\_i\^2\)\), where (Subscript[c, i]) and (Subscript[y, i]) are deviations of (Subscript[C, i]) and (Subscript[Y, i]) from their corresponding means.  The least-square estimate of α is \(TraditionalForm\`α\&^\) = \(TraditionalForm\`\(C\&-\)\) - \(TraditionalForm\`β\&^\)\(TraditionalForm\`\(Y\&-\)\).  Using these two formulas, α and β can be estimated by finding the elements of \(TraditionalForm\`α\&^\) and \(TraditionalForm\`β\&^\) as follows,
({{Observation}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {∑}})({{Y, C, \(y = Y - \(Y\&-\)\), \(c = C - \(C\&-\)\), (y^2), c . 
              y}, {2300, 2145, -113, -67, 12769, 7571}, {2360, 2173, -53, -39, 2809, 2067}, {2395, 2189, -18, -23, 324, 414}, {2407, 2190, -6, -22, 36, 132}, {2389, 2185, -24, -27, 576, 648}, {2430, 2206, 17, -6, 289, -102}, {2395, 2195, -18, -17, 324, 306}, {2413, 2215, 0, 3, 0, 0}, {2430, 2235, 17, 23, 289, 391}, {2467, 2251, 54, 39, 2916, 2106}, {2480, 2279, 67, 67, 4489, 4489}, {2490, 2281, 77, 69, 5929, 5313}, {28956, 26544, 0, 0, 30750, 23335}})
the estimated β,  \(TraditionalForm\`β\&^\) = (23335/30750)= .75886, the estimated α, \(TraditionalForm\`α\&^\) = 2212 - .75886(2413) = 380.87, and the estimated equation is C = 380.87 + .76Y.   The β coefficient of the consumption function is the marginal propensity to consume (MPC), which represents increase in consumption for every one dollar increase in income, β = Δ(C/Δ)Y = .76. 
As you may notice, even for a two variable, simple regression model, finding the coefficients of a regression model needs large amount of numerical calculations.  Fortunately, to day most scientific calculators have built-in programs that can run regression models.  As well, computer programs such as TSP, SPSS, SAS, and others are available for such calculations.  To solve the same problem using Mathematica, list data as pairs of observations then use ListPlot command to plot the data,
Clear[data,  linefit, p1,  p2]
data  = {{2300, 2145}, {2360, 2173}, {2395, 2189}, {2407, 
                2190}, {2389, 2185}, {2430, 2206}, {2395, 2195}, {2413, 
                2215}, {2430, 2235}, {2467, 2251}, {2480, 2279}, {2490, 
                2281}} ;           
p1 = ListPlot[data,  PlotStyle -> {RGBColor[1, 0, 0],  
                      PointSize[ .03]}, AxesLabel -> {"Y",  "C"}];

Although few observations are outliers, the eyeballing of the list plot clearly shows that the relationship between Y and C is more of a linear relation.  Therefore, we fit an equation of a line C = α + βY.  Use the Fit command to fit the line to list of data,
linefit = Fit[data,  {1, Y},  Y]
380.8665040650012` + 
        0.7588617886179492` Y
The equation of the line is C = 380.87 + .76Y.  The plot of the equation and the list plot of the data together is shown below
p2 = Plot[linefit,  {Y,  2200, 2500}];


Show[p1, p2]

⁃  Graphics  ⁃

It is obvious that the least-squares estimate, C = 380.67 + .76Y, passes through several points but not all.  Some of the points lie above the fitted line and others lie below the fitted line. But the estimated line best represents the points with the sum squared errors between the actual points and the fitted line being minimum.   
To fit the best line ar curve to a set of data take the following steps:
	1- Identify the independent and dependent variables.  A variable that determines or controls another variable is called independent variable.  A variable that is controlled or depends on other variables is called dependent variable.  In the example above, consumption (C) depends on income (Y) and not the other way around.  Therefore, consumption is dependent variable and income is independent variable.
	2- Plot the independent variable on the horizontal (x) axis and the dependent variable on the vertical (y) axis. If the data points appear to lie on a straight line, fit an equation of line.  If data are scattered in a non-linear form, decide on one of the non linear functional forms discussed in chapter 2.  If you choose a polynomial function, select the degree of the polynomial by eyeballing the plot or by studying the theoretical relationship between the variables.  For example, production and cost functions, usually, follow a third degree polynomial.  Total revenue function is usually a second degree polynomial.  In general, economic theory is the best starting point for deciding the form of the relationship between the variables.  Eyeballing of the plot gives an indication of the relationship for the specific set of data that you are working with.  Finally, the functional form may be decided by statistical tests of best fit to the data set.
	3- If the plot of the data, or the economic theory indicates no intercept for the line or the curve, constrain your fit to pass through the origin. (Note: In Mathematica command Fit[data, {1, x}, x}], the number "1" in the curved bracket refers to intercept.  To fit a line that passes through the origin do not include "1").  Also, to fit polynomials of higher degree, include the polynomial in the curved bracket.  For example, to fit a third-degree polynomial with no intercept, use the command Fit[data, {x, x^2, x^3}, x].
	4- The fitted model may be used for studying the structural relationship between the variables or for forecasting.  To forecast the future values of the dependent variable or its value at a certain point, an estimated value of the independent variables must be available. 

Example: Demand and Price Elasticity
A businessperson collects the following data on the relationship between the price and the quantity of the product sold in the store.  Find the relationship between the price and quantity and estimate the price elasticity of the demand at P = $7.50.
P:  6.00,  6.30, 6.50,  6.65, 6.75, 8.00, 8.10,  8.25, 7.10, 7.20, 6.90, 6.60, 8.15, 7.70, 8.20
Q:   255,   228,  212,   198,  185,  140,  135,   131,  178,  170,  193,  199,  142,  156, 139
Solution:  Quantity demanded for a product (q) depends on the price of the product (p).  Plot the relationship between p and q to decide on the functional form.  

The plot of the relationship between p and q shows that a linear relationship may be appropriate way of presenting the relationship between p and q.   As in the previous example, make a table to find the elements of the least-square estimators  \(TraditionalForm\`β\&^\) = \(TraditionalForm\`\(∑\+\(i = 1\)\%n\( c\_i\) y\_i\)\/\(∑\+\(i = 1\)\%n c\_i\^2\)\)and  \(TraditionalForm\`α\&^\) = \(TraditionalForm\`\(C\&-\)\) - \(TraditionalForm\`β\&^\)\(TraditionalForm\`\(Y\&-\)\) to estimate α and β in the equation p = α + βp + ϵ.  Check your results with the estimated coefficients \(TraditionalForm\`α\&^\) = 517.13 and \(TraditionalForm\`β\&^\) = -47.01.  The demand function is q = 517.13 - 47.01p.  
To find the price elasticity of demand at p = $7.50, find the corresponding q by substituting for p in the demand equation.  This results in q = 164.55 units.  The price elasticity of demand is defined as  (Subscript[ξ, p])= ((Δq  %)/(Δp  %)) = Δ(q/Δ)p.(p/q), where Δ(q/Δ)p is the slope of the demand function, \(TraditionalForm\`β\&^\) = -47.01.  By substituting the values of p, q, and Δ(q/Δ)p to (Subscript[ζ, p]), the price elasticity of demand is estimated to be (Subscript[ζ, p]) = -2.15.
To solve the problem using Mathematica,
Clear[p, q, data, demandfit]
data = {{6, 255}, {6.30, 228}, {6.50, 212}, {6.65, 
                198}, {6.75, 185}, {8, 140}, {8.10, 135}, {8.25, 131}, {7.10, 
                178}, {7.20, 170}, {6.9, 193}, {6.60, 199}, {8.15, 
                142}, {7.70, 156}, {8.20, 139}};
demandplot =ListPlot[data,PlotStyle -> {RGBColor[1, 0, 0], 
                    PointSize[ .03]}, AxesLabel -> {"p",  "q"}]

⁃  Graphics  ⁃
The eyeballing of the plot shows that the relationship between p and q is a linear relationship.  To fit an equation of line to data, use the Fit command,
demandfit = Fit[data, {1, p}, p]
517.1319152313674` - 
        47.01087387887927` p
The demand equation is q = 517.13 - 47.10p.  To graph the equation, use the Plot command as,
demandline = Plot[demandfit, {p, 5, 10}]

⁃  Graphics  ⁃
and to graph the list plot of data and graph of the demand function together, use the Show command as,
Show[demandplot, demandline]

⁃  Graphics  ⁃
To find the price elasticity of demand at p = 7.50, first estimate q at this price using the estimated demand equation,
demandfit /. p -> 7.50
164.55036113977286`
the estimated quantity corresponding to p = 7.50 is q = 164.55.  By substituting for p, q, and Δ(q/Δ)p in the elasticity formula  (Subscript[ξ, p])= ((Δq  %)/(Δp  %)) = Δ(q/Δ)p.(p/q),  (Subscript[ζ, p]) is estimated to be (Subscript[ζ, p]) = -2.15.

Problems:
1.  Plot the following two points and fit a line to the points.  Fine the errors between the points and the fitted lines.
a- (2, 6)  and  (-1, 4)
b- (0, 4)  and  (5, 8)
c- (1, 5), (3, 8), and  (4, 9)
d- (0, 0), (-1, -1), (1, 2), (-2, -3), and (3, 5)
e- (3, 2), (4, 3), (5, 6), (9, 7), (2, 2), (6, 4), and (4, 4) 
2.  The following data are observations on the price (P) and the quantity demanded (Q) for a product.
P:    6,  7,  6.5,    6,  7.5,   7.3,   7,  7.8,   8,  8.2,  8.5,  7.5,   8,  7.3,   9,  9.5
Q:  67, 65,  67,  66,  67,    65,  66,  65,  64,   65,   65,   66,  65,  66, 60,  59
Plot the relationship between P and Q.  Fit the best line representing the data.  Estimate the quantity demanded for P = 10 and for P = 5.
3.  The following data represents the relationship between labor input (L) and output (Q) in a business.
L:  10,  11,   9,  13,  16,  11,  13,  12,  11,  13,   9,   6,  17,  8,  14,  14,  13,  16,  18
Q:  28,  35, 24,  39,  44,  34,  38,  34,  35,  39, 28, 20,  50, 26,  42, 44,  40,  42,  52
Plot the relationship between L and Q.  Fit the best line representing the data.  Estimate Q for a labor input level of 20.

II.  Fitting Curves
The consumption model may be the best example of the linear relationship between two economic variables.  However, most economic relationships are non-linear, which require fitting curves rather than lines to data.  Economic theory may have strong implication on the functional form of the variables under study.  However, it is always advisable to plot the relationship between the variables and decide the functional form based on economic theory and what the plots represent.  If there is a contrast between the economic theory and what your data presents, you may fit both models, analyze the differences in the fit, and explain why your data does not comply with economic theory.  

The least-square method described in the previous section is applicable only to linear models.  If the model is nonlinear, it should first be linearized by converting the variables, then the least square method can be applied to the converted model.  In practice, the three types of non-linearity that happen are exponential models, polynomial models, and models with rational independent variable.    

Log-Linearizing Exponential Models:  To apply least squares to an exponential model of the form Y = α(X^β)ϵ, apply logarithmic transformation to the model as, lnY = lnα + βlnX + ln∈.  The new model is a log-linear model that can be written as y = a + βx + e, where y, a, x, and e are the natural logarithms of Y, α, X, and ∈.  The least square method can be applied to this model to estimate β and a.  Note that since a = lnα, once a is estimated, the estimated α will be equal to \(TraditionalForm\`α\&^\) = \(TraditionalForm\`E\^a\&^\), where E is the natural number, E = 2.718.  

Example: Demand Function
The following data represents the relationship between price and quantity demanded for a product.  Estimate the demand equation and find the price elasticity of demand.
({{P, 5.50, 5.00, 6.30, 6.80, 5.80, 6.2, 6.5, 5.1, 7.2, 7.5}, {Q, 20.0, 25.0, 14.0, 12.0, 18.0, 15.5, 14.7, 23.8, 11.0, 9.8}})
Solution:  The plot of the data below shows a relationship that seems to be exponential function relationship between P and Q.  Therefore, let's try a function of the form Q = α(P^β)∈.  

To fit a function, first log-linearize the function by applying the natural log transformation, Log Q = Log α + βLog P + Log ∈.  The log-linear equation can be written as LQ = a + βLP + e where, LQ, LP, a, and e are the natural logs of Q, P, α, and ∈, respectively.  Make a table of log of P and Q values and use the least square estimator formulas to estimate a and β as follows
({{observations, P, Q, LP, LQ, \(lp = \ LP - LP\&_\), \(lq = LQ - LQ\&_\), lp*lq, (lp^2)}, {1, 5.5, 20, 1.70, 3.00, - .1097, .2457, - .0269, .0120}, {2, 5, 25, 1.61, 3.22, - .2050, .4689, - .0961, .0420}, {3, 6.3, 14, 1.84, 2.64, .0262, - .1109, - .0029, .0007}, {4, 6.8, 12, 1.92, 2.48, .1025, - .2651, - .0272, .0105}, {5, 5.8, 18, 1.76, 2.89, - .0565, .1404, - .0079, .0032}, {6, 6.2, 15.5, 1.82, 2.74, .0101, - .0092, 0, .0001}, {7, 6.5, 14.7, 1.87, 2.69, .0574, - .0622, - .0036, .0033}, {8, 5.1, 23.8, 1.63, 3.17, - .1852, .4197, - .0777, .0343}, {9, 7.2, 11, 1.97, 2.40, .1597, - .3521, - .0562, .0255}, {10, 7.5, 9.8, 2.01, 2.28, .2005, - .4676, - .0938, .0402}, {∑, 61.9, 163.8, 18.13, 27.51, 0, 0, - .3923, .1718}})
the least-square estimators  \(TraditionalForm\`β\&^\) = \(TraditionalForm\`\(∑\+\(i = 1\)\%n\( lp\_i\) lq\_i\)\/\(∑\+\(i = 1\)\%n lp\_i\^2\)\)= \(TraditionalForm\`\(-\(\(.\)\(\ \)\(3923\)\)\)\/ .1718\) = -2.28 and  \(TraditionalForm\`a\&^\) = \(TraditionalForm\`\(\(\(LQ\)\(\ \)\)\&-\)\)- \(TraditionalForm\`β\&^\)\(TraditionalForm\`\(LP\&-\)\) = 2.75 +2.28(1.814) = 6.89.    Since \(TraditionalForm\`a\&^\) = Log(\(TraditionalForm\`α\&^\)), to find \(TraditionalForm\`α\&^\), take anti-log as, \(TraditionalForm\`α\&^\) = (E^6.89) = 982.40.  Therefore, the demand equation can be written as Q = 982.40(P^(-2.  28)). 
To solve the same problem using Mathematica, first list the data and plot the relationship.
Clear[P, Q, data,  logdata,  plot1,  plot2,  
          fit1]

        data = {{5.5, 20}, {5, 25}, {6.3, 14}, {6.8, 12}, {5.8, 18}, {6.2, 
                15.5}, {6.5, 14.7}, {5.1, 23.8}, {7.2, 11}, {7.5, 
                9.8}};

plot1 = ListPlot[data,PlotStyle -> {RGBColor[1, 0, 0], 
                  PointSize[ .03]},AxesLabel -> {"P", "Q"}]


⁃  Graphics  ⁃
To find the logarithmic values of P and Q take the log of data and call it a name (here, logdata) and fit the equation of line to the transformed data
logdata = N[Log[data]];
fit1  =  Fit[logdata, {1, x}, x]
6.894976875963451` - 
        2.2840588362089185` x
the fitted equation is LogQ = 6.89 - 2.28LogP.    Since \(TraditionalForm\`a\&^\) = Log(\(TraditionalForm\`α\&^\)), to find \(TraditionalForm\`α\&^\), take anti-log as, \(TraditionalForm\`α\&^\) = (E^6.89) = 982.40.  Therefore, the demand equation can be written as Q = 982.40(P^(-2.  28)).   To plot the fitted equation, use the "Plot" command as,
plot2 =  Plot[982.40  P^(-2.28),  {P, 5,  8}]

⁃  Graphics  ⁃
To show the actual data and the plot of the fitted equation together, use the Show command as follows
Show[plot1,  plot2]

⁃  Graphics  ⁃

Converting Polynomial Models:  To apply least squares to a polynomial model of the form Y = α + β(X^n) + ϵ, assume Z = X\(TraditionalForm\`\^n\) and estimate the model Y = α + βZ + ϵ as you would estimate a linear model. 

Example:  Production Function
A manufacturer has collected the following monthly data on the relationship between labor input and output in the operating range of the business for the past twelve month.  Fit a best fitting model to the data.
 ({{L, 23, 21, 22, 26, 28, 25, 23, 20, 22, 24, 25, 29}, {Q, 254, 210, 252, 342, 379, 330, 275, 210, 232, 306, 208, 410}})
 Solution:  The plot of the relationship between L and Q below shows a quadratic from, Q = α + β(L^2)+ ∈.  
         
Let's assume that z = (L^2).  The model can be written as Q = α + βz + ∈ and can be estimated as a linear model.  Make a table of data as follows:
    ({{Observations, L, Q, Z, \(z = Z - Z\&_\), \(q = Q - Q\&_\), zq, (z^2)}, {1, 23, 254, 529, -53.83, -32, 1722.56, 2897.67}, {2, 21, 202, 441, -141.83, -84, 11913.72, 20115.75}, {3, 22, 252, 484, -98.83, -34, 3360.22, 9767.37}, {4, 26, 342, 676, 93.16, 56, 5217.52, 8680.65}, {5, 28, 379, 784, 201.16, 93, 18708.81, 40469.37}, {6, 25, 330, 625, 42.16, 44, 1855.48, 1778.31}, {7, 23, 275, 529, -53.83, -11, 592.13, 2897.67}, {8, 20, 176, 400, -182.83, -110, 20111.30, 33426.81}, {9, 22, 233, 484, -98.83, -53, 5237.99, 9767.37}, {10, 24, 306, 576, -6.83, 20, -136.60, 46.65}, {11, 25, 308, 625, 42.16, 22, 927.74, 1778.31}, {12, 29, 375, 841, 258.17, 89, 22977.13, 66651.75}, {∑, 288, 3432, 6994, 0, 0, 92488.00, 198277.68}})          
  the least-square estimators  \(TraditionalForm\`β\&^\) = \(TraditionalForm\`\(∑\+\(i = 1\)\%n\( z\_i\) q\_i\)\/\(∑\+\(i = 1\)\%n z\_i\^2\)\)= (92488.00/198277.68) = .466 and  \(TraditionalForm\`α\&^\) = \(TraditionalForm\`\(\(\(Q\)\(\ \)\)\&-\)\)- \(TraditionalForm\`β\&^\)\(TraditionalForm\`Z\&_\) = 286 - .466457(582.833) = 14.13. Therefore, the production function can be written as Q = 14.41 + .466(L^2). 
To solve the problem using Mathematica, use the following commands
Clear[L,  Q,  data,  graph1,  graph2,  fit1]
data  =  {{23, 254}, {21, 202}, {22, 252}, {26, 342}, {28, 
                379}, {25, 330}, {23, 275}, {20, 176}, {22, 233}, {24, 
                306}, {25, 308}, {29, 375}};
graph1=ListPlot[data,PlotStyle -> {RGBColor[1, 0, 0], 
                  PointSize[ .03]},AxesLabel -> {"L", "Q"}]

⁃  Graphics  ⁃
\(To\ fit\ a\ quadratic\ form\ Q\  = \ α\  + \ βL\^2 + \  ∈ \ to\ data, use\ the\ Fit\ command\ as, \)
fit1 = Fit[data,  {1, L^2},  L]
14.133328177824694` + 
        0.46645697195683544` (L^2)
to graph the fitted equation, use the Plot command
graph2  =  Plot[fit1,  {L,  20,  30}]

⁃  Graphics  ⁃
To show the actual data and the fitted curve together, use the Show command as,
Show[graph1, graph2]

⁃  Graphics  ⁃

Converting Models Containing Rational Independent Variable:  To apply least squares to a function of the form Y = α + (β/X) + ϵ, assume Z = (1/X) and estimate the model Y = α + βZ + ϵ as you would estimate a linear model.  

Example: Inflation-Unemployment Trade-Off: Phillips Curve
In an empirical study of the relationship between inflation and unemployment for the 1861-1957 period, the British economist A.W. Phillips found an inverse relationship between inflation and unemployment.   Later studies in US economy was supportive of such trade-off, at least in the short run.  Such trade-off  between inflation and unemployment was called Phillips Curve.   Suppose the following ten annual observations on inflation (Y) and unemployment (X) has been collected.  Estimate a best fitting equation to data and find the inflation rate if the unemployment rate were 3%.
({{X, 3.0, 4.5, 4.0, 3.8, 2.5, 2.2, 3.8, 4.5, 5.5, 6.2}, {Y, 5.2, 4.2, 3.2, 4.9, 5.9, 7.3, 4.3, 4.2, 2.6, 2.2}}) 
Solution:   Plot the relationship between inflation and unemployment as follows:
                                   
the plot of the relationship between the two variables shows an inverse relationship between inflation and unemployment.  Let's assume a model of the Phillips curve as Y = α + (β/X) + ∈.  To covert the model to a linear model, let's assume that Z = (1/X).  Therefore, the model can be written as Y = α + βZ + ∈.  Make a table of data and find the least square estimates of α and β.

({{Observations, X, Y, Z = (1/X), \(y = Y - Y\&_\), \(z = Z - Z\&_\), y . z, (z^2)}, {1, 3.0, 5.2, .33, .80, .06, .047, .0034}, {2, 4.5, 4.2, .22, - .20, - .05, .011, .0028}, {3, 4.0, 3.2, .25, -1.20, - .03, .030, .0006}, {4, 3.8, 4.9, .26, .50, - .01, - .006, .0001}, {5, 2.5, 5.9, .40, 1.50, .12, .186, .0156}, {6, 2.2, 7.3, .46, 2.90, .18, .521, .0322}, {7, 3.8, 4.3, .26, - .10, - .01, .001, .0002}, {8, 4.5, 4.2, .22, - .20, - .05, .011, .0028}, {9, 5.5, 2.6, .19, -1.80, - .09, .168, .0087}, {10, 6.2, 2.2, .16, -2.20, - .12, .250, .0129}, {∑, 40.0, 44.0, 2.75, 0, 0, 1.219, .0793}})

the least-squares estimate of  \(TraditionalForm\`β\&^\) = \(TraditionalForm\`\(∑\+\(i = 1\)\%n\( z\_i\) y\_i\)\/\(∑\+\(i = 1\)\%n z\_i\^2\)\)= \(TraditionalForm\`\(1. \ 219\)\/ .0793\) = 15.37 and  \(TraditionalForm\`α\&^\) = \(TraditionalForm\`\(\(\(Y\)\(\ \)\)\&-\)\)- \(TraditionalForm\`β\&^\)\(TraditionalForm\`Z\&_\) = 4.4 - 15.37(.275) = .173. Therefore, the relationship between inflation and unemployment can be written as Y = .173 + (15.37/X).  To estimate the inflation rate corresponding to 3% rate of unemployment, substitute for X = 3, to get Y = 5.30.
To solve the problem using Mathematica, list the data and plot the relation between the two variables
Clear[data,  graph1,  graph2,  fit1]
data  = {{3, 5.2}, {4.5, 4.2}, {4, 3.2}, {3.8, 4.9}, {2.5, 
                5.9}, {2.2, 7.3}, {3.8, 4.3}, {4.5, 4.2}, {5.5, 2.6},  {6.2, 
                2.2}};
graph1 = ListPlot[data,  PlotStyle -> {RGBColor[1, 0, 0],  
                      PointSize[ .03]},\(AxesLabel -> {"Unemployment", "Inflation"}\)];


to fit the equation, use the fit command as,
fit1 =  Fit[data, {1, 1/x}, x]
\(\(\(0.17246446940251126`\)\(\)\) + 
        15.363093780780117`\/x\)
to graph the estimated equation use the Plot command,
graph2= Plot[fit1, {x,  2,  7}, \(AxesLabel -> {"Unemployment", "Inflation"}\)];

to show the actual data and the estimated equation together, use the show command as,
Show[graph1,  graph2]

⁃  Graphics  ⁃
To estimate the output level at an input level of 9 units, evaluate the estimated equation as x->9.
fit1 /. x -> 3
5.29349572966255`

More On Fitting Polynomials:  In fitting polynomials to data, so far, we have assumed a function of the form Y = α + β(X^n) + ϵ.  What if the polynomial functional form is Y = α + (Subscript[β, 1])X + (Subscript[β, 2])(X^2) + ... + ϵ.   Even though we have only one variable (X) as independent variable, the conversion of the model to a linear form changes the nature of the regression to a multi-variable regression model. That is, to transform a third degree polynomial Y = α + (Subscript[β, 1])X + (Subscript[β, 2])(X^2) + (Subscript[β, 3])(X^3)+ ϵ to a linear form, assume Z = (X^2) and W = (X^3). The model can be written as Y = α + (Subscript[β, 1])X + (Subscript[β, 2])Z + (Subscript[β, 3])W + ϵ.   Estimating α and βs in this model is the subject of fitting planes and surfaces to data discussed in the next section.  Fitting planes and surfaces to set of data follows the least squares techniques of estimating α and βs in such a way that the sum squared residuals between actual data and the estimated plane are minimized.  However, the numerical calculations are very much involved and time consuming and using a computer software to estimate the coefficients becomes almost unavoidable.  

Example: Cost Function
The cost function is a relationship between output and cost of producing output.  Suppose the following data represents the relationship between the quantity of output (Q) and cost of producing output (cost)
({{Q, 0, 3, 7, 12, 16, 21, 23, 25, 29, 32, 34}, {Cost, 20, 130, 251, 386, 414, 416, 604, 830, 1082, 1332, 1702}})
Plot the relationship between cost and output and fit the equation representing the relationship.
Solution:  Economic theory would argue that the relationship between cost and output is often a third-degree polynomial with an intercept.  Due to division of labor and initial economies of scale, the total cost initially increases with a decreasing rate.  Later, as the diminishing productivity catches up, total cost increases with an increasing rate.  The list plot of data below supports such relationship between cost and output.
Clear[data,  graph1,  graph2,  fit1]
data  =  {{0, 20}, {3, 130}, {7, 251}, { 12,  
                386}, {16,  414}, {21,  416}, {23, 604}, {25,  
                830},  {29, 1082}, {32, 1332},  {34,  1702}};
graph1 = ListPlot[data,  PlotStyle -> {RGBColor[1, 0, 0],  
                    PointSize[ .03]}, AxesLabel -> {"Q", "Cost"}];

the best functional form representing this data is cost =  α + βQ + γ(Q^2) + δ(Q^3).  Using Mathematica, the coefficients can be estimated as 
fit1 = Fit[data,  {1,  x,  x^2,  x^3},  x]
10.877128615417519` + 
        55.44335902685158` x - 3.5088933652708976` (x^2) + 
        0.09771751078814742` (x^3)
the estimated function is cost = 10.88 + 57.44Q - 3.51(Q^2) + 0.10(Q^3).  The list plot of actual data and the estimated function are graphed together below.
graph2 = Plot[fit1, {x,  0,  40}, AxesLabel -> {"Q", "Cost"}];

Show[graph1,  graph2]

⁃  Graphics  ⁃

Example: Total Product, Arc Marginal Product, and Average Product Functions 
The relationship between labor input (L) and output (Q) is given below, 
({{L, 3, 5, 8, 10, 14, 16, 19, 22, 25, 26}, {Q, 127, 235, 448, 610, 893, 1012, 1168, 1318, 1339, 1335}})
find production function (TP) by fitting a curve to the data.  Find arc marginal product  (AMP) and average product (AP) of labor.  Listplot the AMP and AP data.  Fit appropriate models to each data.  Graph the total product, arc marginal product, and average product curves.  Write your observations on the relationship between the AMP and AP curves.
Solution:  Economic theory assumes a third-degree polynomial between labor input and output in the short-run.  Initially, as labor input increase output increases with increasing rate due to efficiency obtained from division of labor.  In the short-run, assuming capital input are fixed, beyond certain level of labor input (inflection point) diminishing return will catch up and output will increase with a decreasing rate.  As labor input increases further beyond maximum output level, marginal product of labor turns negative and output will decrease.  The graph below shows the listplot of data and the three phases of the production.  
Clear[data,  graph1,  graph2,  fit1]
data  =  {{3, 127},  {5, 235}, {8,  448}, {10, 
                  610}, {14, 893}, {16, 1012}, {19, 1168}, {22, 1318},  {25, 
                  1339}, {26, 1335}};

graph1 = ListPlot[data,  PlotStyle -> {RGBColor[1, 0, 0],  PointSize[ .03]},AxesLabel -> {"Labor Input", "Output"}]


⁃  Graphics  ⁃
The listplot confirms that the mathematical from of the function can be expressed as Q = α + βL + γ(L^2) + λ(L^3)+ ϵ.  To fit the curve to data using Mathematica, use the following command,
fit1 =  Fit[data,  {1, x, x^2, x^3},  x]
-24.604732354644398` + 39.77646115096684` x + 
        3.3550954038457803` (x^2) - 0.110395117137562` (x^3)
the fitted equation is Q = -24.60 + 39.78L + 3.36(L^2) - 0.11(L^3) and the graph of the fitted equation is 
graph2= Plot[fit1, {x, 0, 30},  PlotLabel -> {"TP"},\(AxesLabel -> {"Labor Input", "Output"}\)]

⁃  Graphics  ⁃
to graph the function and the listplot of data together use the following command
Show[graph1, graph2]

⁃  Graphics  ⁃
The arc marginal product of a variable input is defined as increase in total product per unit increase in variable input, assuming other inputs held constant.  Here, the arc marginal product of labor is,  AMP = (DQ/DL), where DQ is the change in Q and DL is the change in labor input.  Average product is total product per unit of input, AP = (Q/L).    Once AMP and AP are generated from the original data, listplot the data to decide on the proper functional forms and fit the functions.  (Note: For generating DQ, DL, and AMP through the program, see Appendix at the end of this chapter).
Clear[AMP,  AP,  fit2,  fit3,  graph3,  graph4]
AMP  =  {54, 71, 81, 70.75, 59.5, 52, 50, 
              7, -4};        
graph3=ListPlot[AMP,  PlotStyle -> {RGBColor[1, 0, 0],  PointSize[ .03]},AxesLabel -> {"Labor Input", "AMP"}]

⁃  Graphics  ⁃
the listplot of AMP data shows that a parabola seems to be the appropriate form of the function
fit2 = Fit[AMP,  {1,  x,  x^2},  x]

43.89285714285704` + 
        17.33154761904762` x - 2.57440476190476` (x^2)
the marginal product function is AMP = 43.89 + 17.33L - 2.57(L^2), the graph of which is presented below,
graph4 = Plot[fit2, {x,  0,  10}, PlotLabel -> {"AMP"}, PlotStyle -> {RGBColor[1, 0, 1]},AxesLabel -> {"Labor Input", "AMP"}];

the following graph shows the estimated curve od AMP and the actual data together
\(\(Show[graph3, graph4]\)\(
\)\)

⁃  Graphics  ⁃
The average product of labor is AP = (Q/L).  Listplot the data to decide the appropriate form of the function.
AP  =  {42.33, 47, 56, 61, 63.79, 63.25, 61.47, 59.91, 
              53.56, 51.35};
ListPlot[AP, PlotStyle -> {RGBColor[1, 0, 0],  
                    PointSize[ .03]}]



⁃  Graphics  ⁃
The AP plot also shows that a parabola is an appropriate form of the function to present the data.   Therefore, fit a function of the form AP = α + βL + γ(L^2)+ ∈
fit3  =  Fit[AP,  {1,  x,  x^2}, x]
32.025333333333236` + 
        10.405727272727242` x - 0.8646969696969664` (x^2)
\(the\ AP\ function\ is\ AP\  = \ 
        32.03\  + \ 10.41  L\  - 
          0.86  L\^2, \ \(\(the\)\(\ \)\(graph\)\(\ \)\(of\)\(\ \)\(which\)\(\ \)\(is\)\(\ \)\(presented\)\(\ \)\(below\)\(\ \)\)\)
graph5 = Plot[fit3, {x,  0,  10}, PlotLabel -> {"AP"}, PlotStyle -> {RGBColor[1, 1, 0]}];

the arc marginal product and average product function are graphed together below
Show[ graph4,  graph5]

⁃  Graphics  ⁃
As the graphs of  AMP and AP show as long as marginal product is higher than average product, average product increases.  The two curve meet at the maximum AP, beyond which the average product of labor will be decreasing.  To see the relationship between total product (TP), marginal product (AMP), and average product (AP), graph all three curve as follows
Show[ graph2]
Show[graph4,  graph5]

⁃  Graphics  ⁃

⁃  Graphics  ⁃
The graphs are similar to the standard TP, AP, and AMP curves in any economics text book.  As long as Q  increases with an increasing rate, AMP is rising.  At the inflection point of the total output curve, AMP reaches maximum and beyond that point it decreases.  As long as AMP is higher than AP, AP is rising.  AMP passes through the maximum point of AP curve, beyond which both curves are declining.   At the maximum output level AMP = 0.

Problems
1- The following data represents total cost (TC) of producing a good at different levels of output (Q).  
({{Q, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {TC, 65, 111, 140, 163, 176, 194, 228, 273, 334, 418, 514}})
a)  Plot the relationship between TC and Q and decide on the degree of the polynomial.
b)  Find marginal cost (MC) of production ( MC is defined as increase in TC for one unit increase in Q).
c)  Find average variable cost (AVC) of production (AVC is defined as (VC/Q)).
d)  Find average total cost (ATC) of production (ATC is defined as (TC/Q))
e)  Plot MC, AVC and ATC.
f)  Fit appropriate polynomials to TC, MC, AVC and ATC.
g)  Show ATC, AVC, and MC together on one coordinate system and comment on the relationship between the three curves.
h)  Find TC corresponding to 11 units of output.
2-   The following data represents total cost (TC) of producing a good at different levels of output (Q).  
({{Q       0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {TC   100 , 116, 128, 135, 144, 158, 184, 228, 295, 386, 519}})
 a)  Plot the relationship between TC and Q and decide on the degree of the polynomial.
b)  Find marginal cost (MC) of production ( MC is defined as increase in TC for one unit increase in Q).
c)  Find average variable cost (AVC) of production (AVC is defined as (VC/Q)).
d)  Find average total cost (ATC) of production (ATC is defined as (TC/Q))
e)  Plot MC, AVC and ATC.
f)  Fit appropriate polynomials to TC, MC, AVC and ATC.
g)  Show ATC, AVC, and MC together on one coordinate system and comment on the relationship between the three curves.
h)  Find TC corresponding to 12 units of output.
3- The following data represents the relationship between labor input (L) and output (Q) of a manufacturing business.
        ({{L   0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {Q   0, 19, 40, 49, 64, 78, 87, 92, 95, 96, 94}})    
   a)  Plot the relationship between L and Q
b)  Find arc marginal product (MP)of labor.
c)  Find average product of labor (AP).
d)  Fit appropriate functions to Q, MP, and AP.
e)  Plot Q, MP, and AP.
f)  Comment on the relationships between the three curves.
g)  Find output level corresponding to 11 units of labor     
4-    The following data represents the relationship between labor input (L) and output (Q) of a manufacturing business.
  ({{L  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {Q  0, 45, 135, 395, 605, 773, 865, 897, 911, 916, 917}})       
  a)  Plot the relationship between L and Q
b)  Find arc marginal product (MP)of labor.
c)  Find average product of labor (AP).
d)  Fit appropriate functions to Q, MP, and AP.
e)  Plot Q, MP, and AP.
f)  Comment on the relationships between the three curves.  
g)  Find output level corresponding to 11 units of labor 

III. Fitting Planes and Surfaces: The ListPlot3D Command
Every economic variable may be explained by a number of other variables.  For example, consumption may depend on price level and interest rate, as well as income.  Output in a manufacturing business may depend on capital and state of the technology, as well as labor input, and etc.  Explaining a variable in terms of  more than one variable requires building multi-variable models and is the subject of multiple regression analysis.  A multi-variate relationship may have linear form or non-linear form.  The form of the function may be decided by using statistical tests or by plotting the relationship between the dependent variable and independent variables and eyeballing the trends. 

Fitting planes and surfaces follows the same principles of fitting line in the least squared method discussed in the previous section.  The objective is to fit a plane to set of data in such a way that the sum squared errors between the actual data and the plane is minimized.  In practice estimating coefficients of multiple regression models requires large amount of data manipulation and calculations.  Therefore, the use of statistical packages such as E-Views, SAS, or SPSS becomes a necessity.  Here, we will use Mathematica to fit some multiple regression models. 

Example:  Production Function
The relationship between labor input (L), capital input (K), and output (Q) is given as
({{L, 0, 2, 3, 5, 6, 9, 12, 14, 15, 15, 15}, {K, 0, 5, 6, 6, 6, 7, 10, 10, 12, 15, 18}, {Q, 0, 24, 30, 34, 46, 64, 68, 68, 78, 90, 102}})
Plot the relationship between labor input and output.
Plot the relationship between labor input and output.
Plot the relationship between labor input, capital input, and output.  
Fit a model explaining output as a function of inputs.  
Find the output level corresponding to 6 units of labor and 6 units of capital
Solution:  To plot the relationship between labor input and output, make a table of data (data1) consisting of labor input and output and list plot the data.  (Note:  For generating data1 through the Mathematica commands, see, 2. Data Manipulation of a Table in Appendix at the end of this chapter)
Clear[data,  data1,  data2,  fit4]
data  =  {{0, 0, 0}, {2, 5, 24}, {3, 6, 30}, {5, 6, 
                  34}, {6, 6, 46}, {9, 7, 64}, {12, 10, 68}, {14, 10, 
                  68}, {15, 12, 78}, {15, 15, 90}, {15, 18, 102}};

\(\(data1 = {{0, 0}, {2, 24}, {3, 30}, {5, 34}, {6, 46}, {9, 
                64}, {12, 68}, {14, 68}, {15, 78}, {15, 90}, {15, 
                102}};\)\(
\)\)
ListPlot[data1,  PlotStyle -> {RGBColor[1, 0, 0],  PointSize[ .03]},AxesLabel -> {"L", "Q"}]


⁃  Graphics  ⁃
To plot the relationship between capital input and output, make a table of data (data2) consisting of capital input and output and list plot the data.
data2  =  {{0, 0}, {5, 24}, {6, 30}, {6, 34}, {6, 
                46}, {7, 64}, {10, 68}, {10, 68}, {12, 78}, {15, 90}, {18, 
                102}};

ListPlot[data2,  PlotStyle -> {RGBColor[1, 0, 0],  PointSize[ .03]},AxesLabel -> {"K", "Q"}]

⁃  Graphics  ⁃
The two graphs above show the relationship between labor input and output and the relationship between capital input and output, respectively.   Although the individual graphs show a nonlinear relationship between each input and output, the graph of the relationship between both inputs and output (below) shows that the relationship may be approximated by a linear surface.
ListPlot3D[data,AxesLabel -> {"L", "K", "Q"}]

⁃  SurfaceGraphics  ⁃
Assuming a linear surface, the production function can be estimated by fitting a model of the form Q = α L + βK.  Using Mathematica, α and β can be estimated by using the "Fit" command as,
\(\(
\)\(fit4\  = \ Fit[data, {x, y}, \ {x, y}]\)\)
2.6656557301718617` x + 3.534050179211471` y
the estimated model is Q = 2.67L + 3.53K, the graph of which is presented below.
Plot3D[fit4,  {x,  0,  6},  {y,  0,  6}]

⁃  SurfaceGraphics  ⁃
To evaluate the output corresponding to L = 6 and K = 6, evaluate the estimated function at this point as,
fit4 /. {x -> 6,  y -> 6}
37.1982354563`
the estimated output corresponding to 6 units of labor input and 6 units of capital input is 37 units.

Example:  Cobb-Douglas Production Function
Data for labor input (L), capital input (K), and output (Q) is given as
L:   1,    2,   1,    3,    3,    2,      4,    4,      4,       4,      3,       3,     5,     5,       5,       5,      5,      4
K:   1,   1,   2,    1,    2,     3,      1,    2,      3,       4,      3,       4,     1,     2,      3,       4,       5,      5
Q: 10,  35, 40, 70, 290, 318, 118, 490, 1100, 2000,  670, 1200, 200, 730, 1700, 3000, 4800, 3000
Plot the relationship between labor input, capital input, and output.  
Fit a model explaining output as a function of inputs.  
Find the output level corresponding to 6 units of labor and 6 units of capital
Solution:  List the data and plot the relationship between the variables. 
Clear[data, Q,  x,  y,  logdata]
\(\(data\  = \ {{1, 1, 10}, \ {2, 1, 35}, \ {1, 2, 40}, {3, 1, 
                70}, {3, 2, 290}, {2, 3, 318}, {4, 1, 118}, {4, 2, 490}, {4, 
                3, 1100}, {4, 4, 2000}, {3, 3, 670}, {3, 4, 1200}, {5, 1, 
                200}, {5, 2, 730}, {5, 3, 1700}, {5, 4, 3000}, {5, 5, 
                4800}, {4, 5, 3000}};\)\(
\)\)
ListPlot3D[data]

⁃  SurfaceGraphics  ⁃
The list plot of the data clearly shows that the relationship between inputs and output is not a linear surface.  Therefore, we may try a Cobb-Douglas model,  Q =ALαKβeϵ . To fit a Cobb-Douglas model, use logarithmic transformation to transform the function to Log Q = Log A + αLog L + βLog K + ϵ, τhen fit a log-linear model to the transformed data.  
\(\(logdata\  = \ N[Log[data]];\)

        Fit[logdata, \ {1, x, y}, {x, y}]\)
Null (2.290629060185684` + 
            1.819329705849946` x + 2.0084831551219056` y)
The loglinear model is LogQ = 2.29 + 1.82LogL + 2LogK.  To write the model in its Cobb-Douglas form, first find A.  Since LogA = 2.29, A = (e^2.29), where e is the natural number.  
N[E^2.29063]
9.881160852005305`
A = 9.88 and the model can be written in its Cobb-Douglas form as Q = 9.88(L^1.82)(K^2).  To plot the function, use Plot3D command as,
Plot3D[
          9.88 x^1.8  y^2.0085,  {x,  0, 10}, {y, 0, 10}]

⁃  SurfaceGraphics  ⁃
To find Q corresponding to L = 6 and K = 6, substitute for L and K in the production function
Q =  9.88  x^1.82  y^2;
Q /. {x -> 6,  y -> 6}
9274.590023781218`
the output corresponding to six units of labor and six units of capital is 9274.59 units.
 
Problems:
1.  Data for labor input (L), capital input (K), and output (Q) is given as
L:   1,    1,   2,    3,    3,    5,      5,    4,      6,       6,      7,       8,     9,    10 
K:   1,   2,   2,    4,    3,     4,      5,    5,      7,       6,      8,       9,     8,    10
Q: 11, 14,  22, 38,  32,   50,    55,  52,     70,    66,     83,     91,   98,   110
Plot the relationship between labor input and output.  
Plot the relationship between capital input and output.
Plot the relationship between labor input, capital input, and output.  
Fit a model explaining output as a function of inputs.  
Find the output level corresponding to 6 units of labor and 6 units of capital
2-    Data for labor input (L), capital input (K), and output (Q) is given as
({{L, 1, 1, 2, 3, 3, 5, 5, 4, 6, 6, 7, 8, 9, 10}, {K, 1, 2, 2, 4, 3, 4, 5, 5, 7, 6, 8, 9, 8, 10}, {Q, 2, 7, 40, 340, 200, 1154, 1730, 1020, 4895, 3720, 9000, 15360, 16460, 31700}})
a)  Plot the relationship between labor input and output.  
b)  Plot the relationship between capital input and output.
c)  Plot the relationship between labor input, capital input, and output.  
d)  Fit a model explaining output as a function of inputs.  
e)  Find the output level corresponding to 11 units of labor and 11 units of capital.
3-    A consumer expresses her total ordinal utility (TU) from consuming two goods x and y as follows.
({{x, 1, 0, 1, 1, 2, 3, 3, 5, 5, 4, 6, 6, 7, 8, 9, 10}, {y, 0, 1, 1, 2, 2, 4, 3, 4, 5, 5, 7, 6, 8, 9, 8, 10}, {U, 0, 0, 1, 1.5 , 2, 3.5, 3, 4.5, 5, 4.5, 6.5, 6, 7.5, 8.5, 8.5, 10}})
a)  Plot the relationship between x, y, and U.
b)  Fit the best fitting function to the data

IV. Finding Exact Fits:  The InterpolatingPolynomial Command
The least-squares method fits the best model of your specification to data.  The estimated model will best generate the data, with the sum squares of errors between the actual points and the estimated model being minimum.  However, the model will not exactly reproduce data.  To reproduce data exactly, you can fit a polynomial that will pass through all the points. In general, for every set of n data points we can fit a polynomial of degree n - 1 which passes through all the points.  The function "InterpolationgPolynomial" in Mathematica estimates a polynomial that fits the data exactly.  Such polynomials may have a limited use, or no use, in applied economics but they may be useful in various algebraic algorithms.

Example:  Fit an exact polynomial to the following four points, A(1,5),  B(3,3),  C(5,6),  D(8,8), and plot the function.  
Solution:  For the four data points of this example a third degree polynomial will fit exactly and will pass through all the four points. List the data and use the Mathematica command InterpolatingPolynomial to find the function.
Clear[data,  interpol]
data  =  {{1, 5},  {3,  3},  {5,  6},  {8, 8}};
interpol  =  InterpolatingPolynomial[data,  x]
Plot[interpol,  {x,  0,  10}]
5 + (-1 + ((5/8) - (19/168) (-5 + x)) (-3 + 
                    x)) (-1 + x)

⁃  Graphics  ⁃

Problems:
Fit an exact polynomial to the following points find the equation of the polynomial and graph it.
1.  (2, 5) and (-1, 6)			
2.  (2,2), (4, -1), and (5, 0)
3.  (0,0), (-1, -3), and (1, 3)		
4.  (0, 3), (4, 2), and (-1, 6)
5.  (4,-1), (5, 3), (1,1), and (-2,0)		
6.  (1, 1),  (3, -1), (0, 5), and (-6, 1)

Appendix: Data Manipulation
1. Generating DQ and DX Using Mathematica:  The data set below is a paired observations on X and Q.  To generate DQ = (Subscript[Q, t]) - (Subscript[Q, t - 1]) and DX = (Subscript[X, t]) - (Subscript[X, t - 1])through the Mathematica commands, load the data manipulation package by using the command <<Statistics`DataManipulation` and list your data as follows,
<< Statistics`DataManipulation`
Clear[data,  L,  Q,  MP,  AP]
data  =  {{2, 13},  {4, 36}, {7, 72}, {8, 87}, {11, 
                  123}, {14, 138}, {16, 140},  {17, 139}, {20, 121}};

by using the command X = Column[data, 1] select the first column of the data set.  This will give the observations on X.   Qs are the second elements of each pair of observation.  Find Q using the command Q = Column[data, 2].
L = Column[data,  1]
{2, 4, 7, 8, 11, 14, 16, 17, 20}
Q  =  Column[data,  2]
{13, 36, 72, 87, 123, 138, 140, 139, 121}
The data set has nine observations.  Since lagging a variable drops one of the observations from the end point (the (9^th) observation here), (Subscript[Q, t - 1]) is generated by the command Drop[Q, {9}].  (Subscript[Q, t]) is generated by taking observations two through nine using the command Take[Q, {2, 9}].  Therefore, DQ is the difference between the two generated sets.  The same applies to DL.  AMP is a table generated by taking the ratio of the two variables, (DQ/DL).
DQ = Take[Q, {2,  9}] - Drop[Q,  {9}]         
{23, 36, 15, 36, 15, 2, -1, -18}
DL  =  Take[L,  {2,  9}]  -  Drop[L,  {9}]
{2, 3, 1, 3, 3, 2, 1, 3}
A  MP = Table[DQ/DL]

{(23/2), 12, 15, 12, 5, 1, -1, -6}
AP is generated by a table of (Q/L).
ap  =  Table[Q/L]
{(13/2), 9, (72/7), (87/8), (123/11), (69/7), (35/4), (139/17), (121/20)}

2. Data Manipulation of a Table:  Suppose you have a three-columns table of data with observations on X, Y, and Z and you would like to make new tables with paired observations on X and Y, X and Z, and Y and Z.  To generate new tables, first load the data manipulation package <<Statistics`DataManipulation`,  type your data set, and use the command Column[data, {1, 2}] for generating a table of Xand Y observations, Column[data, {1, 3}] for generating a table of X and Z observations, and Column[data, {2, 3}] for generating a table consisting of observations on Y and Z. 
<< Statistics`DataManipulation`
Clear[data,  dataxy,  dataxz,  datayz]


data  =  {{0, 0, 0}, {2, 5, 24}, {3, 6, 30}, {5, 6, 
                34}, {6, 6, 46}, {9, 7, 64}, {12, 10, 68}, {14, 10, 68}, {15, 
                12, 78}, {15, 15, 90}, {15, 18, 102}};
dataxy = Column[data,  {1,  2}]
{{0, 0}, {2, 5}, {3, 6}, {5, 6}, {6, 6}, {9, 7}, {12, 10}, {14, 
          10}, {15, 12}, {15, 15}, {15, 18}}
\(\(datayz\)\(\ \)\(=\)\(\ \)\(Column[
            data, \ {2, \ 3}]\)\(	\)\)
{{0, 0}, {5, 24}, {6, 30}, {6, 34}, {6, 46}, {7, 64}, {10, 68}, {10, 
          68}, {12, 78}, {15, 90}, {18, 102}}
dataxz = Column[data,  {1,  3}]	

{{0, 0}, {2, 24}, {3, 30}, {5, 34}, {6, 46}, {9, 64}, {12, 68}, {14, 
          68}, {15, 78}, {15, 90}, {15, 102}}