Hi,
I'm given the data attached and I need to create a model to predict % Body Fat from a linear combination of Waist, Weight, and offset. So far, I have reordered the Waist in numerical order and then created a scatter plot as you can see in the code below. I am not sure how to proceed from here.
Waist=[32 32 33 33 33 34 34 35 36 36 38 38 38 39 40 40 41 41 44 44];
Weight=[175 168 159 188 188 159 146 173 181 175 200 187 188 196 192 240 205 215 246 219]
scatter(Waist, Weight)
xlabel ('Waist (in)')
ylabel ('Weight (lb)')
Thank you so much in advance!!

 Réponse acceptée

Star Strider
Star Strider le 11 Fév 2017
Here you go. I also typed in the ‘Body Fat %’ for you. That is sort of necessary if you want to use it in your equation.
I prefer stem3 to scatter3 because it gives a better sense of the (x,y) relationships of the data.
The Code
Waist=[32 32 33 33 33 34 34 35 36 36 38 38 38 39 40 40 41 41 44 44];
Weight=[175 168 159 188 188 159 146 173 181 175 200 187 188 196 192 240 205 215 246 219];
BF_Pct = [6 21 15 6 22 31 32 21 25 30 10 20 22 9 38 10 27 12 10 28];
Design_Matrix = [ones(size(Waist(:))), Waist(:), Weight(:)]; % Design Matrix
B = Design_Matrix\BF_Pct(:); % Estimate Parameters
BF_Pct_Est = Design_Matrix*B; % Fit Equation
figure(1)
stem3(Waist(:), Weight(:), BF_Pct(:), '-b', 'filled')
hold on
stem3(Waist(:), Weight(:), BF_Pct_Est(:), '-pg', 'filled')
hold off
xlabel ('Waist (in)')
ylabel ('Weight (lb)')
zlabel('Body Fat Percent')
grid on
legend('Data', 'Regression Fit')
view([-20 +24])

4 commentaires

newbie
newbie le 11 Fév 2017
Thank you so much Star Strider!!!!
Now from here, how would I calculate the slope, if it's not too much trouble to ask.
My pleasure!
The slopes (there are two, creating a plane) are ‘B(2)’ and ‘B(3)’. To properly depict the regression plane, you need to plot it:
Wav = linspace(min(Waist), max(Waist),25);
Wev = linspace(min(Weight), max(Weight),25);
BFv = linspace(min(BF_Pct), max(BF_Pct),25);
[Wam,Wem] = meshgrid(Wav, Wev);
Fit_Plane = B(1).*ones(size(Wam)) + B(2).*Wav + B(3).*Wev;
figure(2)
mesh(Wav(:), Wev(:), Fit_Plane)
hold on
stem3(Waist(:), Weight(:), BF_Pct(:), 'bp', 'filled')
hold off
grid on
xlabel('Waist')
ylabel('Weight')
zlabel('Body Fat %')
view([-25 25])
legend('Regression Plane', 'Data')
The relationship between waist size, height, and body fat percentage is nonlinear (and currently controversial, since such derived measures as ‘Body Mass Index’, dating from the 1830s take too few variables into account and so may not be as helpful as originally envisioned). Don’t be discouraged if the fit doesn’t look as good as you might want it to.
(Unknown)
(Unknown) le 11 Fév 2017
Perfect, Thank you so much Star Strider!! :)
Star Strider
Star Strider le 11 Fév 2017
My pleasure!
If it helped you, please add a Vote for it!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by