MASTERSHEET 
Copy/Paste Formulae for Core 1 Data Analysis

>Copy the formula you need
>Paste it into the other workbook you are using
>NOTE: Do NOT alter the formulae in this workbook, these are your templates only.

A. MATHEMATICA COMMANDS FOR CORE 1 (Data) Univariate Data Chapter 1

1. To create a frequency table of data with Tally and percentage, calculate the mode CATEGORICAL DATA

dataset:={"Enter data separated by commas"}
PercentForm[WordFrequency["\",{"\","\","\"}]]
Tally[dataset]
TableForm[Tally[dataset],TableHeadings->{None, {"Column 1","Frequency"}}]
lm:=Commonest[dataset]//N
Print["mode = ",Normal[lm]]

dataset:={S,S,L,M,M,M,L,S,S,M,M,S,L,S,M,M,M,S,S,M}
PercentForm[WordFrequency["S,S,L,M,M,M,L,S,S,M,M,S,L,S,M,M,M,S,S,M",{"S","M","L"}]]
Tally[dataset]
TableForm[Tally[dataset],TableHeadings->{None, {"Column 1","Frequency"}}]
lm:=Commonest[dataset]//N
Print["mode = ",Normal[lm]]

dataset:={S,S,L,M,M,M,L,S,S,M,M,S,L,S,M,M,M,S,S,M}
Tally[dataset]
TableForm[Tally[dataset],FrequencyAllocation[dataset],TableHeadings->{None, {"Column 1","Frequency","Percentage"}}]
lm:=Commonest[dataset]//N
Print["mode = ",Normal[lm]]

2. To calculate Percentage Frequency of a Frequency Table

PercentForm[Solve["Per cent"==(("Count")/("Total Count")),"Per cent"]//N]

PercentForm[Solve["Per cent"==(8/20),"Per cent"]//N]

3. To create a bar chart of data

BarChart[{"Enter frequency values in order, separated by commas"},ChartLabels->{"Enter variable names in double quotation marks and separated by commas"}, ChartStyle->{"Enter colours with a capital letter and separated by commas"}]

BarChart[{40,45,15},ChartLabels->{"S","M","L"}, ChartStyle->{Red,Green,Yellow}]

4. Stacked (Segmented) Bar Chart

BarChart[{{"category 1 segment 1","category 2 segment 1","category 3 segment 1"},{"category 1 segment 2","category 2 segment 2","category 3 segment 2"},{"category 1 segment 3","category 2 segment 3","category 3 segment 3"},{"category 1 segment 4","category 2 segment 4","category 3 segment 4"}},ChartLayout->"Stacked",ChartLegends->{"Thingies","Doohickeys","Whatsits"}]

BarChart[{{1,2,3},{1,3,6},{3,1,4},{0,6,4}},ChartLayout->"Stacked",ChartLegends->{"Thingies","Doohickeys","Whatsits"}]

5. To calculate the Mean, the Standard Deviation

dataset1:={"Enter data separated by commas"}
lm:=Round[Mean[dataset1],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset1],0.01]//N
Print["Standard Deviation = ",Normal[lm]]

dataset1:={176,160,163,157,168,172,173,169}
lm:=Round[Mean[dataset1],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset1],0.01]//N
Print["Standard Deviation = ",Normal[lm]]

6. To calculate the Five-Number Summary: Minimum, (Subscript[Q, 1]),Median, (Subscript[Q, 3]), Maximum, IQR, Box Whisker Plot, Stem Leaf Plot

dataset2:={"Enter data separated by commas"}
lm:=Min[dataset2]//N
Print["Minimum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], Quartiles[dataset2], Quartiles[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["Quartile 1, Quartile 2 could be wrong, Quartile 3= ",Normal[lm]]
lm:=Median[dataset2]//N
Print["Quartile 2 = Median = ",Normal[lm]]
lm:=Max[dataset2]//N
Print["Maximum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], InterquartileRange[dataset2], InterquartileRange[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["IQR = ",Normal[lm]]
lm:=Max[dataset2]-Min[dataset2]//N
Print["Range = ",Normal[lm]]
BoxWhiskerChart[dataset2,"Outliers",BarOrigin->Left]//N
Needs["StatisticalPlots`"]
StemLeafPlot[dataset2]

dataset2:={28,21,21,3,22,31,35,26,27,33,43,31,30,34,48,36,35,23,24}
lm:=Min[dataset2]//N
Print["Minimum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], Quartiles[dataset2], Quartiles[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["Quartile 1, Quartile 2 could be wrong, Quartile 3= ",Normal[lm]]
lm:=Median[dataset2]//N
Print["Quartile 2 = Median = ",Normal[lm]]
lm:=Max[dataset2]//N
Print["Maximum = ",Normal[lm]]
lm:=If[EvenQ[Length[dataset2]], InterquartileRange[dataset2], InterquartileRange[Drop[Sort[dataset2], {((Length[dataset2] + 1)/2)}]]]//N
Print["IQR = ",Normal[lm]]
lm:=Max[dataset2]-Min[dataset2]//N
Print["Range = ",Normal[lm]]
BoxWhiskerChart[dataset2,"Outliers",BarOrigin->Left]//N
Needs["StatisticalPlots`"]
StemLeafPlot[dataset2]

7. Lower Fence  of  Box plot

Solve["Lower Fence"=="Lower Quartile"-1.5*("Upper Quartile"-"Lower Quartile"),"solve for"]

8.  Upper Fence of  Box plot

Solve["Upper Fence"=="Upper Quartile"+1.5*("Upper Quartile"-"Lower Quartile"),"solve for"]

9. To create a Histogram from a list of data

Histogram[{"Enter data separated by commas"},{"Minimum","Maximum","Enter interval spacing"},LabelingFunction->Above,PlotRange->All, ChartLabels->{"\"}, AxesLabel->{"\","\"}]

Histogram[{86,82,96,71,90,78,68,71,68,88,76,74,70,78,69,77,64,80,83,78,88,70,86},{63,98,2},LabelingFunction->Above,PlotRange->All, ChartLabels->{"23 Students Pulse Rates"}, AxesLabel->{"Student Number","Pulse Rate"}]

10. To create a Percentage Histogram from a list of data

rawdata={"Enter data separated by commas"};
bins={Range["Minimum","Maximum","Enter interval spacing"]};
Histogram[rawdata,bins,"Probability",LabelingFunction->(Placed[Panel[PercentForm[Round[#1,0.0001]],FrameMargins->0],Above]&),Ticks->{First@bins,Table[{.01 i,If[Mod[i,5]==0,ToString[i]<>"%",""]},{i,100}]}]

rawdata={86,82,96,71,90,78,68,71,68,88,76,74,70,78,69,77,64,80,83,78,88,70,86};
bins={Range[0,100,10]};
Histogram[rawdata,bins,"Probability",LabelingFunction->(Placed[Panel[PercentForm[Round[#1,0.0001]],FrameMargins->0],Above]&),Ticks->{First@bins,Table[{.01 i,If[Mod[i,5]==0,ToString[i]<>"%",""]},{i,100}]}]

11. To calculate Log Value (Log Scale) or Data Value

Solve["Log Value"==Log10["Data Value"],"solve for"]//N

Solve[-2.4==Log10["Data Value"],"Data Value"]//N

Solve["Log Value"==Log10[1000],"Log Value"]//N

12. To create a Log Histogram With Log Scale

Histogram[{"Enter data separated by commas"},{"Log","Width Specification"},LabelingFunction->Above,PlotRange->All]

Histogram[{1.4,470,36,28,1.0,12000,2600,190,520,10,3.3,530,210,62,6700,9400,6.8,35,0.12,0.023,2.5,56,100,52,87000,0.12,190},{"Log",6},LabelingFunction->Above,PlotRange->All]

13. To create a Stem and Leaf Plot with split stems

Needs["StatisticalPlots`"]
StemLeafPlot[{"Enter data separated by commas"},StemExponent->{Automatic,"UnitDivisions"->2,"DivisionLabels"->{"L","H"}},IncludeStemCounts->True,IncludeEmptyStems->True]

Needs["StatisticalPlots`"]
StemLeafPlot[{16.9,17.3,19.3,18.5,18.2,18.4,19.9,16.7,17.7,16.5,17.0,17.2,17.6,17.1,17.6},StemExponent->{0,"UnitDivisions"->2,"DivisionLabels"->{"L","H"}},IncludeStemCounts->True,IncludeEmptyStems->True]

14. To create a back-to-back Stem and Leaf Plot from two lists of data

Needs["StatisticalPlots`"]
StemLeafPlot[{"Enter data separated by commas"},{"Enter data separated by commas"},StemExponent->Automatic,IncludeStemCounts->True,IncludeEmptyStems->True]

Needs["StatisticalPlots`"]
StemLeafPlot[{16.9,17.3,19.3,18.5,18.2,18.4,19.9,16.7,17.7,16.5,17.0,17.2,17.6,17.1,17.6},StemExponent->0,IncludeStemCounts->True,IncludeEmptyStems->True]

15. To create Parallel Box plots from two lists of data

BoxWhiskerChart[{{"Enter data separated by commas"},{"Enter data separated by commas"}},"Outliers",BarOrigin->Left,ChartLabels->{"\","\"}]//N

16. Normal Distribution ( Z-Score)

Solve[z-score==(((Raw Score-Mean))/("Standard Deviation")),solvefor]

Solve[z==(((18-20.65))/5.73),z]

Solve[.6==(((x-20.65))/5.73),x]

17. Random allocation

RandomSample[{"Enter data separated by commas"},"number of data samples needed"]

RandomSample[{Van, Razi, Gemma,Nimmi, Wong, George,Harry, Zev, Lillie, Lysette, Freya, Simmon, Anna, Mei, Emma, Ali, Moh, Trang, Lani, Sophie},10]

18. Generating a set of normally distributed data

dataset3:=RandomVariate[NormalDistribution["Mean","Standard Deviation"],"number of data samples needed"]
lm:=Round[Mean[dataset3],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset3],0.01]//N
Print["Standard Deviation = ",Normal[lm]]
Histogram[{dataset3},{1}]

dataset3:=RandomVariate[NormalDistribution[25,5],200]
lm:=Round[Mean[dataset3],0.01]//N
Print["Mean = ",Normal[lm]]
lm:=Round[StandardDeviation[dataset3],0.01]//N
Print["Standard Deviation = ",Normal[lm]]
Histogram[{dataset3},{1}]

The distribution is approximately symmetric and bell shaped.

B. MATHEMATICA COMMANDS FOR CORE 1 (Data) Bivariate Data Chapter 2 & 3

1. To create a Scatter Plot (with Regression Line), Residual Plot of Data, calculate Regression Equation, Pearson’s r Value, Coefficient of Determination EV=Explanatory Variables; RV= Response Variables

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel->"Scatterplot"]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

ev:={88.7,67.0,77.5,61.7,86.8,32.4,72.4,77.1,86.5}
rv:={0.3,1.3,2.8,7.6,1.2,5.7,9.4,10.0,0.7}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"- ",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel->"Scatterplot"]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

2. Finding the equation of the line from two points (x1,y1) and (x2,y2) along the line

lm=LinearModelFit[{{(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])}},x,x]
Print["Equation:    y = ",Normal[lm]]

Example
Find the equation of the line that passes through the points (0,3) and (2,2)
lm=LinearModelFit[{{0,3},{2,2}},x,x]
Print[“Equation:    y = “,Normal[lm]]
FittedModel[3.` -0.5` x]
Equation: y = 3 - 0.5x

3. Predict a value from a given equation

"Enter equation here"/.x->"value for prediction"

Example
Predict the value of x = 3 for the equation y = 3 - 0.5x
y=3-0.5x/.x->3
1.5`

4. Calculating slope b by r value,  Sx EV  standard deviation & Sy RV standard deviation

slope[r_,Sx_,Sy_]:=((r*Sy)/Sx)
NSolve[slope["r value Correlation coefficient","Sx Standard deviation of EV","Sy Standard deviation of RV"]=="Slope value",Reals]

slope[r_,Sx_,Sy_]:=((r*Sy)/Sx)
NSolve[slope["r value Correlation coefficient",4.29,1.69]==0.312,Reals]

5. Calculating intercept a by  slope b, (OverTilde[x]) EV mean & (OverTilde[y]) RV mean

intercept[b_,x_,y_]:=y-b*x
NSolve[intercept["slope b","\!\(\*FormBox[RowBox[{StyleBox[OverscriptBox[\"x\", \"~\"],FontWeight->\"Bold\"], StyleBox[\" \",Background->RGBColor[1, 1, 0]], \"EV\", \" \", \"Mean\"}],TraditionalForm]\)","\!\(\*FormBox[RowBox[{StyleBox[OverscriptBox[RowBox[{\"y\", \" \"}], \"~\"],FontWeight->\"Bold\"], StyleBox[\" \",Background->RGBColor[1, 1, 0]], \"RV\", \" \", \"Mean\"}],TraditionalForm]\)"]=="intercept a",Reals]

intercept[b_,x_,y_]:=y-b*x
NSolve[intercept[-0.408,18.0,15.7]=="intercept a",Reals]

C. MATHEMATICA COMMANDS FOR CORE 1 (Data) Data Transformation Chapter 4

1. The New Transformation (Needing high speed laptop)

If[evname=="",assigned,notassigned,evname="(ev)"];
If[rvname=="",assigned,notassigned,rvname="(rv)"];
DialogInput[Grid[{{"EV Name",InputField[Dynamic[evname],String,FieldSize->10],"EV values",InputField[Dynamic[evinput],String,FieldSize->Automatic]},{"RV Name", InputField[Dynamic[rvname],String,FieldSize->10],"RV values",InputField[Dynamic[rvinput],String]},
{"Transformation:",ButtonBar[{"None":>DialogReturn[tfmType=1],"(x^2)":>DialogReturn[tfmType=2],"Log x":>DialogReturn[tfmType=3],"(1/x)":>DialogReturn[tfmType=4],"(y^2)":>DialogReturn[tfmType=5],"Log y":>DialogReturn[tfmType=6],"(1/y)":>DialogReturn[tfmType=7]},ImageMargins->5,ImageSize->{50,40},FrameMargins->5,Background->LightBlue],SpanFromLeft,SpanFromLeft}}],WindowTitle->"Regression analysis."];
tfmlist:={{{"No transformation"},{"y","x"},{"ev","rv"}},{{"x-Squared"},{"y","(x^2)"},{"(ev^2)","rv"}},{{"(Subscript[log, 10])(x)"},{"y","(Subscript[Log, 10])(x)"},{"Log10[ev]","rv"}},{{"reciprocal x"},{"y","(1/x)"},{"(1/ev)","rv"}},{{"y-squared"},{"(y^2)","x"},{"ev","(rv^2)"}},{{"(Subscript[log, 10])(y)"},{"(Subscript[Log, 10])(y)","x"},{"ev","Log10[rv]"}},{{"reciprocal y"},{"(1/y)","x"},{"ev","(1/rv)"}}}
ev:=ImportString[evinput,"List","LineSeparators"->","]
rv:=ImportString[rvinput,"List","LineSeparators"->","]
data:=Thread[ToExpression[Part[tfmlist,tfmType,3]]]
label="Scatterplot with "<>Part[tfmlist,tfmType,1,1]<>" transformation";
xaxislabel=StringReplace[Part[tfmlist,tfmType,3,1],"ev"->evname];
yaxislabel=StringReplace[Part[tfmlist,tfmType,3,2],"rv"->rvname];
xmin=Min[ToExpression[Part[tfmlist,tfmType,3,1]]];
xmax = Max[ToExpression[Part[tfmlist,tfmType,3,1]]];
lm=LinearModelFit[Sort[data],x,x];
Print["Regression equation: ",Part[tfmlist,tfmType,2,1]," = ",Extract[Normal[lm],1],If[D[Normal[lm],x]<0," - "," + "],Abs[Extract[Normal[lm],2]/x],Part[tfmlist,tfmType,2,2],"    ( ",yaxislabel," = ",Extract[Normal[lm],1],If[D[Normal[lm],x]<0," - "," + "],Abs[Extract[Normal[lm],2]/x]," x ",xaxislabel,"  )"]
Print["Pearson's r value = ",If[D[Normal[lm],x]<0,0-(Sqrt[lm["RSquared"]]),(Sqrt[lm["RSquared"]])]]
Print["Coefficient of Determination ((r^2)) =   ",lm["RSquared"]]
Show[ListPlot[data,AxesLabel->{xaxislabel,yaxislabel}],Plot[Normal[lm],{x,xmin,xmax}],PlotLabel->If[tfmType>1,label,"Scatterplot"]]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

2.1. The Squared (x^2) Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{(ev^2),rv,ev}},TableHeadings->{None,{"(ev^2)","rv","ev"}}]//N
data:=Thread[{(ev^2),rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->(x^2)",Style["\tWarning: You have to change x to \!\(\*SuperscriptBox[\(X\), \(\(2\)\(\\ \)\)]\) to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with X Squared Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.2. The Squared (y^2) Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{ev,(rv^2),rv}},TableHeadings->{None,{"ev","(rv^2)","rv"}}]//N
data:=Thread[{ev,(rv^2)}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    (y^2) = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel-> "Scatterplot with Y Squared Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.3. The Logarithmic  Log x Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{Log10[ev],rv,ev}},TableHeadings->{None,{"log ev","rv","ev"}}]//N
data:=Thread[{Log10[ev],rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->Logx",Style["\tWarning: You have to change x to Logx to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with Logx Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.4. The Logarithmic  Log y Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{ev,Log10[rv],rv}},TableHeadings->{None,{"ev","log rv","rv"}}]//N
data:=Thread[{ev,Log10[rv]}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    Logy = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel-> "Scatterplot with Logy Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.5. The X Reciprocal (( 1 )/x)Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{(1/ev)//N,rv,ev}},TableHeadings->{None,{"(1/ev)","rv","ev"}}]//N
data:=Thread[{(1/ev)//N,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm], " ->(1/x)",Style["\tWarning: You have to change x to (1/x) to the equation yourself when writing it!",{Red,Small}]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,0,125}],PlotLabel-> "Scatterplot with X Reciprocal (1/x) Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

2.6. The Y Reciprocal (( 1 )/y) Transformation

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data1=Thread[{ev,rv}];
scatdata1=ListPlot[data1]
TableForm[{{ev,(1/rv)//N,rv}},TableHeadings->{None,{"ev","(1/rv)","rv"}}]//N
data:=Thread[{ev,(1/rv)//N}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    (1/y) = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.00000001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],
Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel-> "Scatterplot with Y Reciprocal (1/y) Transformation"]
ListPlot[lm["FitResiduals"], Filling->Axis, PlotLabel->"Residual Plot"]

D. MATHEMATICA COMMANDS FOR CORE 1 (Data) Time Series Chapter 5

1.Constructing time series plots one graph and two graphs on one plane

ev:= {"insert EV data here, separated by commas"}
rv:={"insert RV data here, separated by commas"}
data:=Thread[{ev,rv}]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]

ev:= {1,2,3,4,5,6,7,8,9,10,11,12}
rv:={0.887,0.906,0.893,0.884,0.875,0.861,0.855,0.848,0.846,0.844,0.833,0.848}
data:=Thread[{ev,rv}]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]

ev:= {"insert EV data here, separated by commas"}
rv:={"insert RV data here, separated by commas"}
rv1:={"insert RV data here, separated by commas"}
data:=Thread[{ev,rv}]
data1:=Thread[{ev,rv1}]
Show[ListLinePlot[{data,data1}],ListPlot[{data,data1}]]

ev:= {1993,1994,1995,1996,1997,1998,1999,2000,2001}
rv:={139.9,141.2,145.5,148.5,152.5,156.0,163.4,167.4,172.5}
rv1:={77.9,76.6,75.3,75.0,74.9,74.9,76.0,76.6,77.1}
data:=Thread[{ev,rv}]
data1:=Thread[{ev,rv1}]
Show[ListLinePlot[{data,data1}],ListPlot[{data,data1}]]

2. Smoothing with Moving-Mean

n:="if a 3-moving-mean, enter a 3 here"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,movingmean},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[movingmean],TableHeadings->{None,{"x value","y value\n (smoothed)"}}]]

n:=3
xdata:={1,2,3,4,5,6,7,8,9,10,11,12}
ydata:={0.887,0.906,0.893,0.884,0.875,0.861,0.855,0.848,0.846,0.844,0.833,0.848}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,movingmean},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[movingmean],TableHeadings->{None,{"x value","y value\n (smoothed)"}}]]

3. Smoothing with Moving-Mean and Centring

n:="if a 2-moving-mean with centring, enter a 2 here"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,MovingAverage[movingmean,2]},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[MovingAverage[movingmean,2]],TableHeadings->{None,{"x value","y value\n (smoothed and centred)"}}]]

n:=4
xdata:={1,2,3,4,5,6,7,8,9,10,11,12}
ydata:={0.887,0.906,0.893,0.884,0.875,0.861,0.855,0.848,0.846,0.844,0.833,0.848}
data:=Thread[{xdata,ydata}]
movingmean:=N[Thread[{MovingAverage[xdata,n],MovingAverage[ydata,n]}]]
Print[ListLinePlot[{data,MovingAverage[movingmean,2]},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[MovingAverage[movingmean,2]],TableHeadings->{None,{"x value","y value\n (smoothed and centred)"}}]]

4. Smoothing with Moving Median

n:="if a 3 median smoothing, enter a 3 here"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmedian:=N[Thread[{MovingMedian[xdata,n],MovingMedian[ydata,n]}]]
Print[ListLinePlot[{data,movingmedian},PlotMarkers->Automatic,ImageSize->Medium],"\t\t\t",TableForm[Table[movingmedian],TableHeadings->{None,{"x value","y value\n (smoothed)"}}]]

5. Comparing 3-Moving and 5-Moving Smoothing Mean/Median

method1:="... -moving smoothing"
method2:="... -moving smoothing"
xdata:={"xdata"}
ydata:={"ydata"}
data:=Thread[{xdata,ydata}]
movingmethod1:=N[Thread[{Moving"Average or Median"[xdata,method1],Moving"Average or Median"[ydata,method1]}]]
movingmethod2:=N[Thread[{Moving"Average or Median"[xdata,method2],Moving"Average or Median"[ydata,method2]}]]
Print[ListLinePlot[{data,movingmethod1,movingmethod2},PlotMarkers->Automatic,ImageSize->Medium,PlotLegends->{"data","method 1","method 2"}],"\t",TableForm[Table[movingmethod1],TableHeadings->{None,{"x value\n(method 1)","y value\n (method 1)"}}],"\t",TableForm[Table[movingmethod2],TableHeadings->{None,{"x value\n(method 2)","y value\n (method 2)"}}]]

Example 1(Mean):

method1:=3
method2:=5
xdata:={1,2,3,4,5,6,7,8,9,10}
ydata:={0.743,0.754,0.737,0.751,0.724,0.724,0.712,0.735,0.716,0.711}
data:=Thread[{xdata,ydata}]
movingmethod1:=N[Thread[{MovingAverage[xdata,method1],MovingAverage[ydata,method1]}]]
movingmethod2:=N[Thread[{MovingAverage[xdata,method2],MovingAverage[ydata,method2]}]]
Print[ListLinePlot[{data,movingmethod1,movingmethod2},PlotMarkers->Automatic,ImageSize->Medium,PlotLegends->{"data","method 1","method 2"}],"\t",TableForm[Table[movingmethod1],TableHeadings->{None,{"x value\n(method 1)","y value\n (method 1)"}}],"\t",TableForm[Table[movingmethod2],TableHeadings->{None,{"x value\n(method 2)","y value\n (method 2)"}}]]

Example 2(Median):

method1:=3
method2:=5
xdata:={1,2,3,4,5,6,7,8,9,10,11,12,13}
ydata:={6,4.2,2,4.5,4.2,4,1,-2,3,4,4.5,3.6,3.9}
data:=Thread[{xdata,ydata}]
movingmethod1:=N[Thread[{MovingMedian[xdata,method1],MovingMedian[ydata,method1]}]]
movingmethod2:=N[Thread[{MovingMedian[xdata,method2],MovingMedian[ydata,method2]}]]
Print[ListLinePlot[{data,movingmethod1,movingmethod2},PlotMarkers->Automatic,ImageSize->Medium,PlotLegends->{"data","method 1","method 2"}],"\t",TableForm[Table[movingmethod1],TableHeadings->{None,{"x value\n(method 1)","y value\n (method 1)"}}],"\t",TableForm[Table[movingmethod2],TableHeadings->{None,{"x value\n(method 2)","y value\n (method 2)"}}]]

Answer 2b: The plot of the raw data, which is essentially a plot of GDP growth smoothed over 1 year, shows a great deal of variability over the whole time period.No clear trend is apparent.When smoothed over a 3 - year period, GDP growth is still variable but to a lesser extent.No clear trend is apparent, but GDP appears to be going through a period of below average growth during the time period Year 7 to Year 9.When smoothed over a 5 - year period, GDP growth is much less variable but clearly shows the period of below average growth during the period Year 7 to Year 9.

6. Seasonal Indices

Deseasonalising / Reseasonalising data:

Solve["deseasonalised figure"==(("actual figure")/("seasonal index")),"Solve for"]//N

Correcting for Seasonality:

(1/(" seasonal index"))

Calculating Seasonal Average

(("add all values together")/("how many seasons there are"))

Calculating Seasonal Index (SI)

(("value for season")/("seasonal average"))

7.Constructing time series plots, Calculating a Regression Equation, Fitting a least-squares line to a time series

ev:={"Enter EV Data Seperated by Commas"}
rv:={"Enter RV Data Seperated by Commas"}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Print["Pearson's Correlation Coefficient r value = ",If[D[Normal[lm],x]<0,"-",""],Round[(Sqrt[lm["RSquared"]]),0.001]]
Print["Coefficient of Determination ((r^2)) =   ",Round[lm["RSquared"],0.001]]
Print["Coefficient of Determination ((r^2)) =   ",PercentForm[lm["RSquared"]]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,Min[ev],Max[ev]}],PlotLabel->"Scatterplot"]
ListPlot[lm["FitResiduals"], Filling->Axis,PlotLabel->"Residual Plot"]

Example 1:

ev:= {1,2,3,4,5,6,7,8,9,10,11,12}
rv:={2149,2140,2124,2118,2118,2114,2091,2064,2059,2038,2029,2013}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,1,12}],PlotLabel->"Scatterplot with Regression Line"]

Example 2:

ev:= {1,2,3,4,5,6,7,8,9,10,11,12}
rv:={893,943,955,858,1005,1026,1043,1040,1261,1151,1115,1267}
data:=Thread[{ev,rv}]
lm=LinearModelFit[Sort[data],x,x]
Print["Regression equation:    y = ",Normal[lm]]
Show[ListLinePlot[data,PlotStyle->Red],ListPlot[data]]
Show[ListPlot[data,AxesLabel->{"ev","rv"}],Plot[Normal[lm],{x,1,12}],PlotLabel->"Scatterplot with Regression Line"]

8. Equation of Least Squares Regression Line: Substitute values of x (EV) in the equation below to make predictions

Solve["Predicted Value"=="yintercept"+"slope"*"x-value","solve for"]//N