HW8
pdf
keyboard_arrow_up
School
University of New South Wales *
*We aren’t endorsed by this school
Course
2089
Subject
Statistics
Date
Jan 9, 2024
Type
Pages
14
Uploaded by ElderEnergyFly29
HOMEWORK ASSIGNMENT 8
EGM 3344
Problems from Chapra book chapters 14, 15
Questions answered: 14.1, 14.5, 14.8, 14.11, 14.18, 15.5, 15.6, 15.5
14.1 Given the data
0.90 1.42 1.30 1.55 1.63
1.32 1.35 1.47 1.95 1.66
1.96 1.47 1.92 1.35 1.05
1.85 1.74 1.65 1.78 1.71
2.29 1.82 2.06 2.14 1.27
(a) the mean
μ
μ = ∑ 𝑎?? ?𝑎???? ÷ number of values
=
40.61
25
= 1
.6244
(b) median
𝑀??𝑖𝑎? = ?𝑖???? ?𝑎???
= 1.65
(
c) mode
𝑀??? = ???? ?????? ?𝑎???
= 1
.35 𝑎?? 1.47
The data is multimodal.
(d) range
?𝑎??? = ℎ𝑖?ℎ??? − ?????? ?𝑎???
= 2.29 − 0.9
= 1
.39
(e) standard deviation
𝜎
𝜎 = √?𝑎?𝑖𝑎???
?𝑎?𝑖𝑎??? =
1
?
∑(?
𝑖
− ??𝑎?) = 0.115184
𝑛
𝑖=1
𝜎
= 0
.339388
(f) variance
?𝑎?𝑖𝑎??? =
1
?
∑
(?
𝑖
− ??𝑎?) = 0
.115184
𝑛
𝑖=1
2
(g) coefficient of variation.
?????𝑖?𝑖??? ?? ?𝑎?𝑖𝑎?𝑖?? =
𝜎
𝜇
× 100%
=
0.339388
1.6244
× 100%
= 20
.89
3
14.5
Use least-squares regression to fit a straight line
Along with the slope and intercept, compute the standard error of the estimate and the correlation
coefficient. Plot the data and the regression line. Then repeat the problem, but regress
x
versus
y
—
that is, switch the variables. Interpret your results.
SEE MATLAB CODE question145
% Given data
x = [0 2 4 6 9 11 12 15 17 19];
y = [5 6 7 6 9 8 8 10 12 12];
% Perform y vs. x regression and calculate statistics
[slope_y_vs_x, intercept_y_vs_x, SEE_y_vs_x, r_y_vs_x] = performRegression(x, y);
% Perform x vs. y
[slope_x_vs_y, intercept_x_vs_y, SEE_x_vs_y, r_x_vs_y] = performRegression(y, x);
% results for y vs. x
disp(
'y vs. x:'
);
fprintf(
'y = %.5fx + %.5f\n'
, slope_y_vs_x, intercept_y_vs_x);
fprintf(
'SEE: %.4f\n'
, SEE_y_vs_x);
fprintf(
'r: %.4f\n'
, r_y_vs_x);
% results for x vs. y
disp(
'x vs. y:'
);
fprintf(
'x = %.5fy + %.5f\n'
, slope_x_vs_y, intercept_x_vs_y);
fprintf(
'SEE: %.4f\n'
, SEE_x_vs_y);
fprintf(
'r: %.4f\n'
, r_x_vs_y);
% Function to perform regression and calculate statistics
function
[slope, intercept, SEE, r] = performRegression(x, y)
coeff = polyfit(x, y, 1);
slope = coeff(1);
intercept = coeff(2);
y_pred = slope * x + intercept;
residuals = y - y_pred;
SSR = sum(residuals.^2);
SEE = sqrt(SSR / (length(x) - 2));
r = corrcoef(x, y);
r = r(1, 2);
end
>> question145
y vs. x:
y = 0.35915x + 4.88812
SEE: 0.8511
r: 0.9449
x vs. y:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
4
x = 2.48614y + -11.13494
SEE: 2.2393
r: 0.9449
5
14.8
Beyond the examples in Fig. 14.13, there are other models that can be linearized
using transformations. For example,
4
4
x
x
y
e
=
Linearize this model and use it to estimate a4 and b4 based on the following data. Develop
a plot of your fit along with the data.
Code:
% Given Data
x = [0.1 0.2 0.4 0.6 0.9 1.3 1.5 1.7 1.8];
y = [0.75 1.25 1.45 1.25 0.85 0.55 0.35 0.28 0.18];
% Linearized Variables X and Y
X = x;
Y = log(y./x);
% ./ is elementwise division operator
p = polyfit(X,Y,1);
A = p(2);
B = p(1);
alpha4 = exp(A);
beta4 = B;
% print results
fprintf(
'Coefficients of fit :- \n\t alpha4 = %.4f \n\t beta4 = %.4f\n'
,alpha4,beta4)
% Ploting
x_plot = linspace(0.1,1.8);
y_plot = alpha4*x_plot.*exp(beta4*x_plot);
plot(x,y,
'.'
,x_plot,y_plot,
'-'
)
legend(
'Data Points'
,
'Fitted Curve'
,
'location'
,
'Best'
)
ylabel(
'y'
);
Output:
Coefficients of fit :
alpha4 = 9.6618
beta4 = -2.4733
Graph:
6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
7
14.11
Determine an equation to predict metabolism rate as a function of mass based on
the following data. Use it to predict the metabolism rate of a 200-kg tiger.
See MATLAB code
‘
question1411
’
Code:
% data
mass = [400; 70; 45; 3; 0.3; 0.16];
% Mass in kg
metabolism = [270; 82; 50; 4.8; 1.45; 0.97];
% Metabolism rate in calories per day
coeff = polyfit(mass, metabolism, 1);
slope = coeff(1);
intercept = coeff(2);
% Predict tiger
mass_tiger = 200;
metabolism_tiger = slope * mass_tiger + intercept;
% Display the linear regression equation and the predicted metabolism rate for the
tiger
fprintf(
'Metabolism Rate = %.2f * Mass + %.2f\n'
, slope, intercept);
fprintf(
'Predicted Metabolism Rate for a 200-kg tiger: %.2f calories per day\n'
,
metabolism_tiger);
output:
question1411
Metabolism Rate = 0.66 * Mass + 11.15
Predicted Metabolism Rate for a 200-kg tiger: 143.21 calories per day
8
14.18
The following data show the relationship between the viscosity of SAE 70 oil and
temperature. After taking the log of data, use linear regression to find the equation of the
line that best fits the data and the
r
2
value.
See MATLAB code
‘
question1418
’
Code:
% data
temperature = [26.67, 93.33, 148.89, 315.56];
viscosity = [1.35, 0.085, 0.012, 0.00075];
% natural log of the data
log_temperature = log(temperature);
log_viscosity = log(viscosity);
% Fit a straight line to transformed data
coeff = polyfit(log_temperature, log_viscosity, 1);
slope = coeff(1);
intercept = coeff(2);
% Calculate the predicted values of log(viscosity)
log_viscosity_pred = polyval(coeff, log_temperature);
% Calculate the sum of squared residuals
SSR = sum((log_viscosity - log_viscosity_pred).^2);
% Calculate the total sum of squares
SST = sum((log_viscosity - mean(log_viscosity)).^2);
% Calculate the R-squared value
r_squared = 1 - SSR / SST;
% Display the linear regression equation and the R-squared value
fprintf(
'Linear Regression Equation (log-transformed data): log(viscosity) = %.4f *
log(temperature) + %.4f\n'
, slope, intercept);
fprintf(
'R-squared value: %.4f\n'
, r_squared);
Output:
Linear Regression Equation (log-transformed data): log(viscosity) = -3.0134 * log(temperature)
+ 10.5492
R-squared value: 0.9757
9
15.3
fit a cubic polynomial to the following data:
Along with the coefficients, determine
r
2
and
S
y/x
.
See MATLAB code
‘
question1530
’
Code:
% data
x = [3, 4, 5, 7, 8, 9, 11, 12];
y = [1.6, 3.6, 4.4, 3.4, 2.2, 2.8, 3.8, 4.6];
% Fit a cubic polynomial
coefficients = polyfit(x, y, 3);
%coefficients
cubic_poly = polyval(coefficients, x);
% Calculate SSR and SST
SSR = sum((y - cubic_poly).^2);
SST = sum((y - mean(y)).^2);
%R-squared
r_squared = 1 - SSR / SST;
disp(
'Coefficients of the cubic polynomial:'
);
disp(coefficients);
fprintf(
'R^2 (coefficient of determination): %.3f\n'
, r_squared);
output:
Coefficients of the cubic polynomial:
0.0467
-1.0412
7.1438
-11.4887
R^2 (coefficient of determination): 0.829
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
10
15.6
Use multiple linear regression to derive a predictive equation for dissolved oxygen
concentration as a function of temperature and chloride based on the data from Table P15.5.
Use the equation to estimate the concentration of dissolved oxygen for a chloride concentration
of 15 g/L at
T
= 12 °C. Note that the true value is 9.09 mg/L. Compute the percent relative error
for your prediction. Explain possible causes for the discrepancy.
Code:
% given data
T = [0 5 10 15 20 25 30];
C = [0 10 20];
o = [14.6 12.8 11.3 10.1 9.09 8.26 7.56;
12.9 11.3 10.1 9.03 8.17 7.46 6.85;
11.4 10.3 8.96 8.08 7.35 6.73 6.20];
% Reshape data for regression
T = repmat(T, 3, 1);
C = kron(C, ones(1, 7));
% Perform multiple linear regression
X = [ones(21, 1), T(:), C(:)];
coeff = X \ o(:);
% Extract coefficients
a0 = coeff(1);
a1 = coeff(2);
a2 = coeff(3);
% Estimate the concentration of dissolved oxygen for C = 15 g/L and T = 12°C
C_pred = 15;
T_pred = 12;
o_pred = a0 + a1 * T_pred + a2 * C_pred;
% Compute the percent relative error
true_value = 9.09;
percent_error = abs(o_pred - true_value) / true_value * 100;
% Display the results
fprintf(
'Estimated Dissolved Oxygen Concentration: %.2f mg/L\n'
, o_pred);
fprintf(
'Percent Relative Error: %.2f%%\n'
, percent_error);
11
output:
Estimated Dissolved Oxygen Concentration: 9.26 mg/L
Percent Relative Error: 1.83%
12
15.15
Given the data
use least-squares regression to fit
(a) a straight line
(b) a power equation
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
13
(c) a saturation-growth-rate equation
(d) a parabola.
14
Plot the data along with all the curves. Is any one of the curves superior? If so, justify.
The saturation-growth-rate equation is superior
-
Best fit to data points
-
highest R^2 value
Related Documents
Recommended textbooks for you

Glencoe Algebra 1, Student Edition, 9780079039897...
Algebra
ISBN:9780079039897
Author:Carter
Publisher:McGraw Hill
Recommended textbooks for you
- Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw Hill

Glencoe Algebra 1, Student Edition, 9780079039897...
Algebra
ISBN:9780079039897
Author:Carter
Publisher:McGraw Hill