In[]:=
Clear["Global`*"]
We shall use the schoolKids dataset:
We shall use the schoolKids dataset:
In[]:=
schoolKids=
;
Extract Height and Weight data (columns 4 and 5) from the dataset
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.
Evaluate Mathematica’s ListPlot function to generate a scatterplot of Weight compared to Height.
In[]:=
xyVarNamesList={"Height","Weight"};
In[]:=
scatterplotHtWt=ListPlot[xyHtWt,FrameTrue,FrameLabelxyVarNamesList,PlotLabel"Scatter Plot with x=Height and y=Weight",ImageSize400,PlotRangeFull,AspectRatio1]
Out[]=
Use Mathematica’s LinearModelFit function to create a linear fit of the data.
Use Mathematica’s LinearModelFit function to create a linear fit of the data.
In[]:=
linFit=LinearModelFit[xyHtWt,{1,x},x]
Out[]=
FittedModel
In[]:=
(*checkforthemodel*)linFit["RSquared"]
2
R
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.
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.
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.
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.
Create a plot of the mean prediction bands.
Combine the plots for the mean and the mean prediction bands with the other plots.
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.
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.