Fletcher Monthly Average Temperatures

Andy Long
Spring, 2020

Data from Fletcher: Monthly Means of 
Mean, Min, and Max Temperatures, 
Thirty Year Averages, 
Period 1959 to 1988 (Means and Maxs, p. 81), and 
Period 1949-1978 (Mins, p. 82)

DecimalDate=Table[i+1/24,{i,0,1,1/12}];
meanTempData={24.1,27.7,39.6,49.0,60.7,70.3,73.5,70.1,65.0,53.8,41.6,29.5,24.1};
maxTempData={30.5,37.3,46.6,60.2,72.7,81.9,84.9,80.1,76.7,64.5,50.0,36.5,30.5};
minTempData={15.5,17.8,27.5,37.8,48.6,58.7,61.8,59.9,53.4,40.2,33.0,21.9,15.5};

Model Means

data=Transpose[{DecimalDate,meanTempData}];meanlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
meanlm["ParameterTable"]
meanlm["RSquared"]
meanlm["AdjustedRSquared"]
meanlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=meanlm["FitResiduals"];

months={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan"};
sizes=Table[Large,{i,1,13}];
markers=Transpose[{months,sizes}];

p0 = ListPlot[data,PlotStyle->{Black,PointSize[Large]}];
(* 
Thanks
https://mathematica.stackexchange.com/questions/190153/how-to-use-a-different-symbol-for-each-point-in-a-list-plot/190154
*)
p1=ListPlot[List /@  data, 
PlotMarkers->markers,
PlotLabel->"Wood County Mean Temperature, by Month (1959-1988)",
PlotRange->{{-.1,1.1},{15,80}},
AxesLabel->{"Time of Year","Temperature (F)"},
ImageSize->Large];
p2=Plot[meanlm[x],{x,0,1},PlotStyle->{Blue,Dashed}];
p3=Plot[32,{x,0,1},PlotStyle->{Gray,Dashed}];
all1=Show[p1,p0,p2,p3]

Model Maxs

data=Transpose[{DecimalDate,maxTempData}];
maxlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
maxlm["ParameterTable"]
maxlm["RSquared"]
maxlm["AdjustedRSquared"]
maxlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=maxlm["FitResiduals"];
SSE=residuals.residuals

p0 = ListPlot[data,PlotStyle->{Black,PointSize[Large]}];
(* 
Thanks
https://mathematica.stackexchange.com/questions/190153/how-to-use-a-different-symbol-for-each-point-in-a-list-plot/190154
*)
p1=ListPlot[List /@  data, 
PlotMarkers->markers,
PlotLabel->"Wood County Mean(Maximum) Temperature, by Month (1959-1988)",
PlotRange->{{-.1,1.1},{20,90}},
AxesLabel->{"Time of Year","Temperature (F)"},
ImageSize->Large];
p2=Plot[maxlm[x],{x,0,1},PlotStyle->{Red,Dashed}];
p3=Plot[32,{x,0,1},PlotStyle->{Gray,Dashed}];
all2=Show[p1,p0,p2,p3]

Model Mins

data=Transpose[{DecimalDate,minTempData}];minlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
minlm["ParameterTable"]
minlm["RSquared"]
minlm["AdjustedRSquared"]
minlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=minlm["FitResiduals"];
SSE=residuals.residuals

({{"", "Estimate", "Standard Error", "t\[Hyphen]Statistic", "P\[Hyphen]Value"}, {m, 39.56754893731769`, 0.3841803431377574`, 102.99212243435828`, 1.8246721243631091`*^-16}, {a, 22.896826680428372`, 0.5239658365964125`, 43.699083186724586`, 9.461947252172229`*^-13}, {e, , \[Placeholder], 78.81392536958182`, 2.6416121305435042`*^-15}})

p0 = ListPlot[data,PlotStyle->{Black,PointSize[Large]}];
p1=ListPlot[List /@  data, 
PlotMarkers->markers,
PlotLabel->"Wood County Mean(Minimim) Temperature, by Month (1949-1978)",
PlotRange->{{-.1,1.1},{0,70}},
AxesLabel->{"Time of Year","Temperature (F)"},
ImageSize->Large];
p2=Plot[minlm[x],{x,0,1},PlotStyle->{Red,Dashed}];
p3=Plot[32,{x,0,1},PlotStyle->{Gray,Dashed}];
all3=Show[p1,p0,p2,p3]

All Together Now!

p1=ListPlot[List /@  data, 
PlotMarkers->markers,
PlotLabel->"Wood County Extreme Temperatures and Models, by Month (30-year average)",
PlotRange->{{-.1,1.2},{0,70}},
AxesLabel->{"Time of Year","Temperature (F)"},
ImageSize->Large];
all3=Show[p1,p0,p2,p3];
Show[all3,all2,all1,PlotRange->All]

iris=Import["/Users/longa/Desktop/NKU/classes/000 2020Spring/mat375/Fletcher/analysis/alldata.csv","CSV"];
header=iris[[1]];
readData=iris[[2;;]];
splitData=Transpose[readData];
data=Transpose[{splitData[[2]],splitData[[3]]}];

alllm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
alllm["ParameterTable"]
alllm["RSquared"]
alllm["AdjustedRSquared"]
alllm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=alllm["FitResiduals"];
SSE=residuals.residuals
Histogram[residuals]

p0 = ListPlot[data,PlotStyle->{Black,PointSize[Medium]}];
p1=ListPlot[data, 
PlotLabel->"Wood County Extreme and Mean Temperature",
PlotRange->{{-.1,1.1},{-40,120}},
AxesLabel->{"Day","Temperature (F)"},
ImageSize->Large]
p2=Plot[alllm[x],{x,0,1},PlotStyle->{Blue}];
p3=Plot[32,{x,0,1},PlotStyle->{Gray,Dashed}];
p4mu=Plot[meanlm[x],{x,0,1},PlotStyle->{Blue,Dashed}];
p4min=Plot[minlm[x],{x,0,1},PlotStyle->{Brown,Dashed}];
p4max=Plot[maxlm[x],{x,0,1},PlotStyle->{Red,Dashed}];
all=Show[p1,p0,p2,p3,p4mu,p4min,p4max,PlotRange->{{-.1,1.1},{-40,120}}]
all=Show[p1,p0,p2,p3,PlotRange->{{-.1,1.1},{-40,120}}]

Now let’s pull all the separate data sets in, so that we can colorize that graph above:

iris=Import["/Users/longa/Desktop/NKU/classes/000 2020Spring/mat375/Fletcher/analysis/minmindata.csv","CSV"];
header=iris[[1]];
minminData=iris[[2;;]];
iris=Import["/Users/longa/Desktop/NKU/classes/000 2020Spring/mat375/Fletcher/analysis/maxmindata.csv","CSV"];
header=iris[[1]];
maxminData=iris[[2;;]];
iris=Import["/Users/longa/Desktop/NKU/classes/000 2020Spring/mat375/Fletcher/analysis/minmaxdata.csv","CSV"];
header=iris[[1]];
minmaxData=iris[[2;;]];
iris=Import["/Users/longa/Desktop/NKU/classes/000 2020Spring/mat375/Fletcher/analysis/maxmaxdata.csv","CSV"];
header=iris[[1]];
maxmaxData=iris[[2;;]];

data=minminData;
minminlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
minminlm["ParameterTable"]
minminlm["RSquared"]
minminlm["AdjustedRSquared"]
minminlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=minminlm["FitResiduals"];
Histogram[residuals]

data=maxminData;
maxminlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
maxminlm["ParameterTable"]
maxminlm["RSquared"]
maxminlm["AdjustedRSquared"]
maxminlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=maxminlm["FitResiduals"];
Histogram[residuals]

data=minmaxData;
minmaxlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
minmaxlm["ParameterTable"]
minmaxlm["RSquared"]
minmaxlm["AdjustedRSquared"]
minmaxlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=minmaxlm["FitResiduals"];
Histogram[residuals]

data=maxmaxData;
maxmaxlm=NonlinearModelFit[data,m+a*Sin[2π*(t-e)],{{m,50},{a,25},{e,.26}},t, MaxIterations->100000]
maxmaxlm["ParameterTable"]
maxmaxlm["RSquared"]
maxmaxlm["AdjustedRSquared"]
maxmaxlm["ParameterConfidenceIntervals"]
SST=(weight-Mean[weight]).(weight-Mean[weight])
residuals=maxmaxlm["FitResiduals"];
Histogram[residuals]

p0a = ListPlot[minminData,PlotStyle->{Blue,PointSize[Medium]}];
p0b = ListPlot[maxminData,PlotStyle->{Cyan,PointSize[Medium]}];
p0c = ListPlot[minmaxData,PlotStyle->{Green,PointSize[Medium]}];
p0d = ListPlot[maxmaxData,PlotStyle->{Red,PointSize[Medium]}];
p1=ListPlot[minminData, 
PlotLabel->"Wood County Extreme Temperatures",
PlotRange->{{-.1,1.1},{-40,120}},
AxesLabel->{"Day","Temperature (F)"},
ImageSize->Large];
p2=Plot[alllm[x],{x,0,1},PlotStyle->{Black}];
p3=Plot[32,{x,0,1},PlotStyle->{Gray,Dashed}];
p4minmin=Plot[minminlm[x],{x,0,1},PlotStyle->{Blue}];
p4maxmin=Plot[maxminlm[x],{x,0,1},PlotStyle->{Cyan}];
p4minmax=Plot[minmaxlm[x],{x,0,1},PlotStyle->{Green}];
p4maxmax=Plot[maxmaxlm[x],{x,0,1},PlotStyle->{Red}];
allDataTogether=Show[p1,p0a,p0b,p0c,p0d,p2,p3,p4maxmin,p4maxmax,p4minmin,p4minmax,PlotRange->{{-.1,1.1},{-40,120}}]

Manipulate[
Show[allDataTogether,
ListPlot[{{day,alllm[day]}}],Plot[alllm[day]+(maxmaxlm[day]-maxminlm[day])*PDF[NormalDistribution[day,sigma],x]/PDF[NormalDistribution[day,sigma],day],{x,day-.3,day+.3},PlotRange->All]
],
{{sigma,0.037},0.01,.3},
{{day,.3},0,1}
]