This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the MD toolbar button for help on Markdown). When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
as of August 28, 2014, superseding the version of August 24. Always use the most recent version.
install.packages("nasaweather", repos='http://cran.us.r-project.org')
## package 'nasaweather' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Max\AppData\Local\Temp\RtmpGKc440\downloaded_packages
#downloads 'nasaweather' from cran website
library("nasaweather", lib.loc="C:/Program Files/R/R-3.1.1/library")
#references 'fueleconomy' in R library
storms<-storms
#assigns the variables in the data set, storms, to the variable named 'data'
head(storms)
## name year month day hour lat long pressure wind type
## 1 Allison 1995 6 3 0 17.4 -84.3 1005 30 Tropical Depression
## 2 Allison 1995 6 3 6 18.3 -84.9 1004 30 Tropical Depression
## 3 Allison 1995 6 3 12 19.3 -85.7 1003 35 Tropical Storm
## 4 Allison 1995 6 3 18 20.6 -85.8 1001 40 Tropical Storm
## 5 Allison 1995 6 4 0 22.0 -86.0 997 50 Tropical Storm
## 6 Allison 1995 6 4 6 23.3 -86.3 995 60 Tropical Storm
## seasday
## 1 3
## 2 3
## 3 3
## 4 3
## 5 4
## 6 4
#displays the first 6 sets of variables
tail(storms)
## name year month day hour lat long pressure wind type
## 2742 Nadine 2000 10 21 6 33.3 -53.5 1000 50 Tropical Storm
## 2743 Nadine 2000 10 21 12 34.1 -52.3 1000 50 Tropical Storm
## 2744 Nadine 2000 10 21 18 34.8 -51.3 1000 45 Tropical Storm
## 2745 Nadine 2000 10 22 0 35.7 -50.5 1004 40 Extratropical
## 2746 Nadine 2000 10 22 6 37.0 -49.0 1005 40 Extratropical
## 2747 Nadine 2000 10 22 12 39.0 -47.0 1005 35 Extratropical
## seasday
## 2742 143
## 2743 143
## 2744 143
## 2745 144
## 2746 144
## 2747 144
#displays the last 6 sets of variables
summary(storms)
## name year month day
## Length:2747 Min. :1995 Min. : 6.0 Min. : 1
## Class :character 1st Qu.:1995 1st Qu.: 8.0 1st Qu.: 9
## Mode :character Median :1997 Median : 9.0 Median :18
## Mean :1997 Mean : 8.8 Mean :17
## 3rd Qu.:1999 3rd Qu.:10.0 3rd Qu.:25
## Max. :2000 Max. :12.0 Max. :31
## hour lat long pressure
## Min. : 0.00 Min. : 8.3 Min. :-107.3 Min. : 905
## 1st Qu.: 3.50 1st Qu.:17.2 1st Qu.: -77.6 1st Qu.: 980
## Median :12.00 Median :25.0 Median : -60.9 Median : 995
## Mean : 9.06 Mean :26.7 Mean : -60.9 Mean : 990
## 3rd Qu.:18.00 3rd Qu.:33.9 3rd Qu.: -45.8 3rd Qu.:1004
## Max. :18.00 Max. :70.7 Max. : 1.0 Max. :1019
## wind type seasday
## Min. : 15.0 Length:2747 Min. : 3
## 1st Qu.: 35.0 Class :character 1st Qu.: 84
## Median : 50.0 Mode :character Median :103
## Mean : 54.7 Mean :103
## 3rd Qu.: 70.0 3rd Qu.:125
## Max. :155.0 Max. :185
#displays a summary of the variables
#Assign the data types
storms$month=as.factor(storms$month)
#makes the variable "month" a factor
storms$year=as.factor(storms$year)
#makes the variable "year" a factor
#Boxplot
boxplot(pressure~month,data=storms, xlab="Month", ylab="Pressure (psi)")
#boxplot of the air pressures from storms of each month
boxplot(pressure~year,data=storms, xlab="Year", ylab="Pressure (psi)")
#boxplot of the air pressures from storms of each year
# ANOVA
#Month
model_month=aov(pressure~month,data=storms)
anova(model_month)
## Analysis of Variance Table
##
## Response: pressure
## Df Sum Sq Mean Sq F value Pr(>F)
## month 6 62467 10411 31.8 <2e-16 ***
## Residuals 2740 897236 327
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#performs an anova test for storm month
#Year
model_year=aov(pressure~year,data=storms)
anova(model_year)
## Analysis of Variance Table
##
## Response: pressure
## Df Sum Sq Mean Sq F value Pr(>F)
## year 5 22560 4512 13.2 1e-12 ***
## Residuals 2741 937143 342
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#performs an anova test for storm year
#Month and Year
model_month_year=aov(pressure~month*year,data=storms)
anova(model_month_year)
## Analysis of Variance Table
##
## Response: pressure
## Df Sum Sq Mean Sq F value Pr(>F)
## month 6 62467 10411 34.24 < 2e-16 ***
## year 5 25274 5055 16.63 3.3e-16 ***
## month:year 18 45920 2551 8.39 < 2e-16 ***
## Residuals 2717 826042 304
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#performs an anova test for the interaction of storm month and year
summary(storms$month)
## 6 7 8 9 10 11 12
## 83 251 720 947 569 170 7
#displays the amount of data points in each month
june<-storms$month=="6"
#assigns all of the data of month 6 to the vector, june
summary(storms[june,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 982 994 1000 1000 1010 1020
#displays a summary of the air pressure data for the month of June
july<-storms$month=="7"
#assigns all of the data of month 7 to the vector, july
summary(storms[july,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 960 995 1000 1000 1010 1020
#displays a summary of the air pressure data for the month of july
august<-storms$month=="8"
#assigns all of the data of month 8 to the vector, august
summary(storms[august,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 929 979 995 990 1000 1010
#displays a summary of the air pressure data for the month of August
sept<-storms$month=="9"
#assigns all of the data of month 9 to the vector, sept
summary(storms[sept,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 921 971 990 985 1000 1020
#displays a summary of the air pressure data for the month of September
oct<-storms$month=="10"
#assigns all of the data of month 10 to the vector, oct
summary(storms[oct,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 905 982 996 991 1000 1020
#displays a summary of the air pressure data for the month of October
nov<-storms$month=="11"
#assigns all of the data of month 11 to the vector, nov
summary(storms[nov,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 933 987 998 993 1000 1010
#displays a summary of the air pressure data for the month of November
dec<-storms$month=="12"
#assigns all of the data of month 12 to the vector, june
summary(storms[dec,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 979 981 985 985 989 990
#displays a summary of the air pressure data for the month of December
#Year
summary(storms$year)
## 1995 1996 1997 1998 1999 2000
## 724 536 186 483 411 407
#displays the amount of data points in each month
nfive<-storms$year=="1995"
#assigns all of the data of 1995 to the vector, nfive
summary(storms[nfive,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 919 979 995 989 1000 1020
#displays a summary of the air pressure data for the year of 1995
nsix<-storms$year=="1996"
#assigns all of the data of 1996 to the vector, nsix
summary(storms[nsix,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 933 979 994 989 1000 1020
#displays a summary of the air pressure data for the year of 1996
nseven<-storms$year=="1997"
#assigns all of the data of 1997 to the vector, nseven
summary(storms[nseven,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 946 991 1000 997 1000 1010
#displays a summary of the air pressure data for the year of 1997
neight<-storms$year=="1998"
#assigns all of the data of 1998 to the vector, neight
summary(storms[neight,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 905 980 996 990 1000 1010
#displays a summary of the air pressure data for the year of 1998
nnine<-storms$year=="1999"
#assigns all of the data of 1999 to the vector, nnine
summary(storms[nnine,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 921 971 992 985 1000 1020
#displays a summary of the air pressure data for the year of 1999
tt<-storms$year=="2000"
#assigns all of the data of 2000 to the vector, tt
summary(storms[tt,"pressure"])
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 941 984 997 993 1010 1010
#displays a summary of the air pressure data for the year of 2000
#Month
qqnorm(residuals(model_month), ylab="Month Residuals")
qqline(residuals(model_month))
#produces a Q-Q normal plot for the storm month with a normal fit line
#Year
qqnorm(residuals(model_year), ylab="Year Residuals")
qqline(residuals(model_year))
#produces a Q-Q normal plot for the storm year with a normal fit line
#Month and Year
qqnorm(residuals(model_month_year), ylab="Month/Year Interaction Residuals")
qqline(residuals(model_month_year))
#produces a Q-Q normal plot for the interaction between the storm month and year with a normal fit line
interaction.plot(storms$month,storms$year,storms$pressure)
#creates a plot that shows the interaction of the year and month on a storm's pressure
#Month
plot(fitted(model_month),residuals(model_month))
#Year
plot(fitted(model_year),residuals(model_year))
#Month and Year
plot(fitted(model_month_year),residuals(model_month_year))