In[]:=
Clear["Global`*"]

We shall use the schoolKids dataset:

In[]:=
schoolKids=
Name
Gender
Age
Height
Weight
1
Agatha
F
12
57
83.7
2
Allan
M
14
68.9
111.5
3
Ann
F
11
51.3
50.5
4
Betty
F
13
65
98.2
5
Cindy
N
13
61.9
100.3
6
George
M
15
67
133
7
Ginger
F
12
59.4
84
8
Harry
M
14
64.2
103
9
Jamie
M
13
57.6
93.5
10
Jan
F
11
57
83
11
Johnny
N
13
62
83.5
12
Julie
F
13
63.2
113
13
Leonore
F
12
56.7
77
14
Liz
F
14
64
90.2
15
Michelle
F
15
66
111
16
Mildred
F
11
51.6
54
17
Paul
M
16
71
149
18
Roscoe
M
12
64.2
126.5
19
Steven
M
13
61
86
20
Tim
M
11
55
52
;

Extract Height and Weight data (columns 4 and 5) from the dataset

In[]:=
heightList=Values[Normal[schoolKids[All,4]]];​​weightList=Values[Normal[schoolKids[All,5]]];
In[]:=
(*constructalistof(height,weight)pairs*)​​xyHtWt=Transpose[{heightList,weightList}]
Out[]=
{{57,83.7},{68.9,111.5},{51.3,50.5},{65,98.2},{61.9,100.3},{67,133},{59.4,84},{64.2,103},{57.6,93.5},{57,83},{62,83.5},{63.2,113},{56.7,77},{64,90.2},{66,111},{51.6,54},{71,149},{64.2,126.5},{61,86},{55,52}}

Evaluate Mathematica’s ListPlot function to generate a scatterplot of Weight compared to Height.

In[]:=
xyVarNamesList={"Height","Weight"};
In[]:=
scatterplotHtWt=ListPlot[​​xyHtWt,​​FrameTrue,​​FrameLabelxyVarNamesList,​​PlotLabel"Scatter Plot with x=Height and y=Weight",​​ImageSize400,​​PlotRangeFull,​​AspectRatio1​​]
Out[]=

Use Mathematica’s LinearModelFit function to create a linear fit of the data.

In[]:=
linFit=LinearModelFit[xyHtWt,{1,x},x]
Out[]=
FittedModel
-170.+4.32x

In[]:=
(*check
2
R
forthemodel*)​​linFit["RSquared"]
Out[]=
0.814679
In[]:=
(*findMinandMaxforHeight*)​​xMax=Max[heightList];​​xMin=Min[heightList];
In[]:=
(*plotthelinearfit*)​​linePlot=Plot[linFit[x],{x,xMin,xMax},PlotStyle->Green]
Out[]=

Now we combine the scatter plot and the line plot using the Show function.
We shall define a local variable which is the list of objects we want to include in our fit plot. We will keep adding to the list as our work progresses.

In[]:=
graphicsInPlot={scatterplotHtWt,linePlot};​​Show[graphicsInPlot]
Out[]=

Create a plot for the mean of Weight.

In[]:=
(*DefineaplotfortheMean*)​​meanPlot=Plot[Mean[weightList],{x,xMin,xMax},PlotStyle{Orange,Dashing[Tiny]}]
Out[]=

Create a plot of the mean prediction bands.

Combine the plots for the mean and the mean prediction bands with the other plots.

Extra: Add tooltips to the points in the scatter plot so that the name of the child associated with the point appears in the tooltip rather than the (x,y) pair when you hover your cursor over a particular point.