This R markdown highlights ways you can manipulate and plot data in R using both the console and R markdown. Data taken from the US Army on the observed change in temperature with the combination of wind in Antartica.
The first challenge in R is simply loading a data set into the R in a way that's usable in the console. To begin, the data set must first be imported into R's environment (if this data is coming from Excel, make sure it is a csv file), and then must be loaded in with the code:
Windchill2 <- read.csv("/Users/matthewhecking/Documents/Intermediate Stats using R/Windchill2.csv")
This code is specific to your computer, to find this info, simply locate the file, right click and choose “get info”, the file's pathway should be listed within.
After the data set is loaded, we can double check the file by using the command:
head(Windchill2)
## windchill speed temp
## 1 33 5 35
## 2 27 5 30
## 3 21 5 25
## 4 16 5 20
## 5 12 5 15
## 6 7 5 10
This gives us the first 5 lines of the data set, and shows us that the file has been successfully loaded into R.
After the data set is loaded into R, we can now begin to analyze it. The first step of this is to attach the file, using the command:
attach(Windchill2)
This allows R to identify the data set as a table with variables and factors. Next, we can preform a general linear model, which can be preformed by typing:
fit = aov(lm(speed ~ windchill + temp))
summary(fit)
## Df Sum Sq Mean Sq F value Pr(>F)
## windchill 1 5427 5427 128 <2e-16 ***
## temp 1 22526 22526 529 <2e-16 ***
## Residuals 167 7109 43
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The extremely low P values shown by the comparison between temp and speed, and windchill and speed proves the interaction between the variables. We can see this interaction visually by graphing the data, using the term “interaction.plot”
interaction.plot(speed, temp, windchill, main = "Wind Chill", xlab = "wind speed",
ylab = "air temperature", )
This gives us a good graphical representation of the data, showing the interaction of wind speed and air temperature to create the windchill effect.