mindata=Import["C:\\Users\\bookw\\Google Drive\\School\\MAT 375\\MiniProject3\\Tabligbo Min Data.csv"];
maxdata=Import["C:\\Users\\bookw\\Google Drive\\School\\MAT 375\\MiniProject3\\Tabligbo Max Data.csv"];
rainfall=Import["C:\\Users\\bookw\\Google Drive\\School\\MAT 375\\MiniProject3\\Tabligbo Temp Rain.csv"];

years=Rest[mindata[[All,1]]]; (* This is the years starting in 1960 *)
mintemp=Rest[mindata[[All,2]]]; (* Minimum temperatures starting in 1960 *)
maxtemp=Rest[maxdata[[All,2]]]; (* Maximum temperatures starting in 1960 *)
rain=Rest[rainfall[[All,4]]]; (* The rainfall starts in 1965 *)
rainYears=Rest[rainfall[[All,1]]]; (* Years starting in 1965 *)
rainmin=Rest[rainfall[[All,2]]];(* The minimum temperatures starting in 1965 *)
rainmax=Rest[rainfall[[All,3]] (* The maximum Temperatures starting in 1965 *)

raindata=Transpose[{rainYears,rain}];

(*Taking out Outliers*)

notoutQ[x_]:=Part[x,2]<309

raindataFixed=Select[raindata,notoutQ];

(*rainfall with outliers*)

(*rainfall Linear Model with just x*)

BoxWhiskerChart[rain,"Outliers",PlotLabel->"Box Plot of the Rainfall"]

ListPlot[raindata,PlotRange->Automatic]

rainln=LinearModelFit[raindata,x,x]

ListPlot[rainln["FitResiduals"],Filling-> Axis]

rainln["ParameterTable"]
rainln["RSquared"]

Show[ListPlot[raindata,PlotRange->Automatic],Plot[rainln[x],{x,1965,2015}]]

The Best Model with Outliers

(*Rainfall Linear Model with Sines and Cosines*)

rainlncurvey=LinearModelFit[raindata,{x,Sin[2 Pi x],Cos[2 Pi x]},x]

ListPlot[rainlncurvey["FitResiduals"],Filling-> Axis]

rainlncurvey["ParameterTable"]
rainlncurvey["RSquared"]

Show[ListPlot[raindata,PlotRange->Automatic],Plot[rainlncurvey[x],{x,1965,2015}]]

Histogram[rainlncurvey["FitResiduals"]]

(*Rainfall Linear Model with More Sines and Cosines*)

rainlncurvey2=LinearModelFit[raindata,{x,Sin[2 Pi x],Cos[2 Pi x],Sin[(2 Pi x)/12],Cos[(2 Pi x)/12]},x]

ListPlot[rainlncurvey2["FitResiduals"],Filling-> Axis]

rainlncurvey2["ParameterTable"]
rainlncurvey2["RSquared"]

Show[ListPlot[raindata,PlotRange->Automatic],Plot[rainlncurvey2[x],{x,1965,2015}]]

(*Rainfall Linear Model with Sines and Cosines and quadratic*)

rainlncurveySquared=LinearModelFit[raindata,{x,Sin[2 Pi x],Cos[2 Pi x],(x^2)},x]

ListPlot[rainlncurveySquared["FitResiduals"],Filling-> Axis]

rainlncurveySquared["ParameterTable"]
rainlncurveySquared["RSquared"]

Show[ListPlot[raindata,PlotRange->Automatic],Plot[rainlncurveySquared[x],{x,1965,2015}]]

The Best Model without Outliers

(*Rainfall Linear Model with Sines and Cosines*)

rainlncurveyFixed=LinearModelFit[raindataFixed,{x,Sin[2 Pi x],Cos[2 Pi x]},x]

ListPlot[rainlncurveyFixed["FitResiduals"],Filling-> Axis,PlotLabel->"Residuals of Rainfall"]

rainlncurveyFixed["ParameterTable"]
rainlncurveyFixed["RSquared"]
rainlncurveyFixed["RSquared"]-rainlncurvey["RSquared"]

Show[ListPlot[raindataFixed,PlotRange->Automatic],Plot[rainlncurveyFixed[x],{x,1965,2015}],Frame->True,PlotLabel->"Rainfall vs Time",FrameLabel->{"Time","Rainfall"}]

Histogram[rainlncurveyFixed["FitResiduals"],PlotLabel->"Histogram of the Residuals"]

(*Max Temperature vs rain stuff*)

MaxTemprain=Transpose[{rainmax,rain}];

Show[ListPlot[MaxTemprain,PlotRange->Automatic],Frame->True,PlotLabel->"Rainfall vs Maximum Temperature",FrameLabel->{"Maximum Temperature","Rainfall"}]

(*min temperature vs rainfall*)

MinTemprain=Transpose[{rainmin,rain}];

Show[ListPlot[MinTemprain,PlotRange->Automatic],Frame->True,PlotLabel->"Rainfall vs Minimum Temperature",FrameLabel->{"Minimum Temperature","Rainfall"}]

(*min Max temperature*)
MinMaxrain=Transpose[{rainmin,rainmax}];
Show[ListPlot[MinMaxrain,PlotRange->Automatic],Frame->True,PlotLabel->"Minimum vs Maximum Temperature",FrameLabel->{"Minimum Temperature","Maximum Temperature"}]

(*outliers for rainfall*)

Sort[rain]

Quartiles[Sort[rain]]

InterquartileRange[Sort[rain]]

23.2-1.5*112.55`

135.75+1.5*112.55`

Rainy Season April-October

309.6, 309.8, 313.3, 315.3, 325.5 - possible outliers
May 1978: 325.5
September 1968: 315.3
October 2002: 313.3

BoxWhiskerChart[rain,"Outliers"]

Sort[Transpose[{rain,rainYears}]];

Contour Stuff and 3D Stuff

𝒟=SmoothKernelDistribution[Transpose[{mintemp,maxtemp}]];
dens=ContourPlot[PDF[𝒟,{x,y}]//Evaluate,{x,Min[mintemp],Max[mintemp]},{y,Min[maxtemp],Max[maxtemp]},PlotRange->All,PlotPoints->50,Contours->15,ColorFunction->"TemperatureMap", PlotLabel->"Contour Plot of Min and Max Temperatures",Frame->True,FrameLabel->{"Minimum Temperatures","Maximum Temperatures"}]

dens=Plot3D[PDF[𝒟,{x,y}]//Evaluate,{x,Min[mintemp],Max[mintemp]},{y,Min[maxtemp],Max[maxtemp]},PlotRange->All,PlotPoints->50,Contours->15,ColorFunction->"TemperatureMap",PlotLabel->"Contour Plot of Min and Max Temperatures",AxesLabel->{"Minimum Temperature","Maximum Temperature",None}]
ListPointPlot3D[Transpose[{rainmin,rainmax,rain}],PlotRange->All,ColorFunction->"TemperatureMap"]

raintable=Table[{i+1965,j,rain[[12*(i-1)+j]]},{i,1,50,1},{j,1,12,1}];
ListPointPlot3D[raintable,PlotRange->All,ColorFunction->"TemperatureMap"]

dens=Plot3D[PDF[𝒟,{x,y}]//Evaluate,{x,Min[mintemp],Max[mintemp]},{y,Min[maxtemp],Max[maxtemp]},PlotRange->All,PlotPoints->50,ColorFunction->"TemperatureMap"];
scalerain=rain*.08/Max[rain];
(* I'm plotting two points, on the surface and the height above (representing the amount of rainfall). It would be nice to plot the segment joining them, a little pogo stick dancing along in time. Also to label the points by month. *)
Manipulate[
p1=ListPointPlot3D[{{rainmin[[t]],rainmax[[t]],scalerain[[t]]}
,{rainmin[[t]],rainmax[[t]],PDF[𝒟,{rainmin[[t]],rainmax[[t]]}]+scalerain[[t]]}},PlotRange->{0,0.10},PlotStyle->{Black,PointSize[0.02+scalerain[[t]]]}];
Show[dens,p1],
{{t,1},1,Length[rain],1}
]

Here are linear models for mintemp, maxtemp, and rainfall. I used my favorite power-of-2 periods: one year, half a year, and a quarter of a year:

minmodel=LinearModelFit[Transpose[{years,mintemp}],{1,x,
Sin[2Pi (1 x)],Cos[2Pi (1 x)],
Sin[2Pi ( x/2)],Cos[2Pi ( x/2)],
Sin[2Pi (x/3)],Cos[2Pi (x/3)],
Sin[2Pi (x/4)],Cos[2Pi (x/4)]
},x];
maxmodel=LinearModelFit[Transpose[{years,maxtemp}],{1,x,
Sin[2Pi (1 x)],Cos[2Pi (1 x)],
Sin[2Pi ( x/2)],Cos[2Pi ( x/2)],
Sin[2Pi (x/3)],Cos[2Pi (x/3)],
Sin[2Pi (x/4)],Cos[2Pi (x/4)]
},x];
rainmodel=LinearModelFit[Transpose[{rainYears,rain}],{1,x,
Sin[2Pi (1 x)],Cos[2Pi (1 x)],
Sin[2Pi ( x/2)],Cos[2Pi ( x/2)],
Sin[2Pi (x/3)],Cos[2Pi (x/3)],
Sin[2Pi (x/4)],Cos[2Pi (x/4)]
},x];
minmodel["ParameterTable"]
minmodel["RSquared"]

maxmodel["ParameterTable"]
maxmodel["RSquared"]

rainmodel["ParameterTable"]
rainmodel["RSquared"]