Info about R Markdown

R Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

Part 3A. Non-spatial Statistics

Import Data

If your R Markdown is NOT in the same folder as your data, please set your working directory using setwd() first. Here is an example setwd("\\medusa\StudentWork\(Your UTOR ID)\GGR276\Lab1"). You will need to change the code to reflect your personal directory. Otherwise, you may skip this step and continue to import data by reading your aviationfacilities.csv file. You may view the data by clicking the aviationfacilities in the Environment window or type code View(DataSet). Click on the little green triangle on the right to run current chunk.

  • For testing where there is any error in any line of code, you should run the script line by line and check how they work carefully.
    • Any errors in your code will be displayed in the bottom left Console window of RStudio, which will help you pinpoint where the error lies.
    • If there is an error, try selecting each line of code individually and running the script one by one. This will tell you which line of code is causing the error.
aviationfacilities <- read.csv("aviationfacilities.csv", sep = ',', header = TRUE)

Descriptive Statistics of aviation facilities

Now that we have data imported, we are ready to calculate median, mean, range and quantiles of the elevation.

summary(aviationfacilities$ELEV)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    -223     275     755    1189    1273   12442

Next, we will calculate the standard deviation of the elevation (ELEV). If there are missing values in your dataset, simply add na.rm = TRUE to your code to tell the R to remove NAs in the calculation. Like this: sd(aviationfacilities$ELEV, na.rm=TRUE).

sd(aviationfacilities$ELEV, na.rm = TRUE)
## [1] 1491.002

Subset for Florida

Create a subset of aviation facilities in Florida.

aviationfacilities_fl <- subset(aviationfacilities, STATE_CODE == "FL")

Descriptive Statistics of Elevation

Question 7: Now it is your turn to write the code to calculate the median, mean, range, interquartile range, and standard deviation of the aviation facilities elevation in Florida (2 marks)

#TODO
summary(aviationfacilities_fl$ELEV)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.00   19.45   55.00   69.11   98.00  709.00
median(aviationfacilities_fl$ELEV, na.rm=TRUE)
## [1] 55
mean(aviationfacilities_fl$ELEV, na.rm=TRUE)
## [1] 69.10834
min(aviationfacilities_fl$ELEV, na.rm=TRUE)
## [1] 0
max(aviationfacilities_fl$ELEV, na.rm=TRUE)
## [1] 709
IQR(aviationfacilities_fl$ELEV, na.rm=TRUE)
## [1] 78.55
sd(aviationfacilities_fl$ELEV, na.rm = TRUE)
## [1] 64.22694

Type your response here (include units, round to 1 decimal place): For median of the aviation facilities elevation in Florida is 55, mean is 69.1, the min is 0 and the max is 709 which nrings us to the range from 0 to 709, and for interquartile range, it is 3rdQu-1stQu, which is 98-19.5 which brings us to the interquartile range equals to 78.5, and the standard deviation is 64.2.

Question 8: According to the boxplot below, would you use median or mean as your central tendency measure? Explain and justify your choice? (2 marks)

Type your response here:
I would prefer using median as my central tendency measure rather than mean because most of the data packed together at the outliers. That said, these extreme of the FL data would not accurately represent the center of the data if using mean as the indicator. Thus, I would use median.

boxplot(aviationfacilities_fl$ELEV)

Part 3B. Mapping Mean and Weighted Mean Centre

Visualize the locations of the Florida airports (A) and the mean and weighted mean centres according to the elevation.

FL_airports <- aviationfacilities_fl[aviationfacilities_fl$SITE_TYPE_CODE == "A", ]
plot(FL_airports$LONG_DECIMAL, FL_airports$LAT_DECIMAL, xlab="Longitude", ylab="Latitude", main = "Airports in Florida", xlim=c(-88, -80), ylim=c(24, 33))
n<-nrow(FL_airports[1])
mc_x<-sum(FL_airports$LONG_DECIMAL)/n
mc_y<-sum(FL_airports$LAT_DECIMAL)/n
points(mc_x,mc_y,'p',pch=15,cex=2,col="blue")
wmc_x <- sum(as.numeric(FL_airports$ELEV * FL_airports$LONG_DECIMAL), na.rm = TRUE) / sum(FL_airports$ELEV, na.rm = TRUE)
wmc_y <- sum(as.numeric(FL_airports$ELEV * FL_airports$LAT_DECIMAL), na.rm = TRUE) / sum(FL_airports$ELEV, na.rm = TRUE)
points(wmc_x, wmc_y,'p',pch=15,cex=2,col='red')
legend("topright", legend = c("Mean centre", "Weighted mean centre"), pch = c(15,15), col = c("blue","red"))

Question 9: Produce comments (i.e., a detailed explanation for each parameter in the code) that describes the execution of the statements given to you in the above example. Make sure you provide a description for each set of statements and organize your answer in a manner similar to the following example. (16 marks)

Example: setwd ("\\medusa\StudentWork\(Your UTOR ID)\GGR276\Lab1")

The setwd() command tells R the current folder to look into when searching for data, saving outputs etc.

Explain what is occurring in each of the following lines of code:

  1. aviationfacilities <- read.csv("aviationfacilities.csv", sep = ',', header = TRUE)
  2. plot(FL_airports$LONG_DECIMAL, FL_airports$LAT_DECIMAL, xlab="Longitude", ylab="Latitude", main = "Airports in Florida", xlim=c(-88, -80), ylim=c(24, 33))
  3. n<-nrow(FL_airports[1])
  4. mc_x<-sum(FL_airports$LONG_DECIMAL)/n mc_y<-sum(FL_airports$LAT_DECIMAL)/n
  5. points(mc_x,mc_y,'p',pch=15,cex=2,col="blue")
  6. wmc_x <- sum(as.numeric(FL_airports$ELEV * FL_airports$LONG_DECIMAL), na.rm = TRUE) / sum(FL_airports$ELEV, na.rm = TRUE) wmc_y <- sum(as.numeric(FL_airports$ELEV * FL_airports$LAT_DECIMAL), na.rm = TRUE) / sum(FL_airports$ELEV, na.rm = TRUE)
  7. points(wmc_x, wmc_y,'p',pch=15,cex=2,col='red')
  8. legend("topright", legend = c("Mean centre", "Weighted mean centre"), pch = c(15,15), col = c("blue","red"))

Type your response here: a)imports data fromCSV file to R that names aviationfacilities.csv. Then, orders R that the values in the file are separated by commas, where the header is true indicates that the first row of the file contains the column names. b)The code orders R to create a scatter plot for spatial distribution of airport and thier locations within the region of Flordia, where the longitude is assoicated and plotted on the x-axis and the latitude is assoicated and plotted on the y-axis, the axes are now labeled in presenting its purpose in serving “Longitude” and “Latitude” accordingly using xlab and ylab. With main, it is to make the title of the plot diagram is to be labelled “Airports in Florida.” Lastly, the range of xlim and ylim show the x axis is setting the measurement of its range from -88 to -80 and the y axis range is 24 to 33 through xlim and ylim. Its purpose is to make use of the map that is only relevant to florida distribution and numbers from unsed infomration. c)The code orders R to calculate the number of rows from using the data of florida airports as the total number of florida airports, here, it is represented as n when communicating. d)The code orders R to calculate the mean centre for Florida airports.On top of the mean centre, it takes in consideration by calculating and measuring with the total sumup of florida airports longitude divided by the amount and number of airports for mean centre of longitude. Meanwhile, it also calculates from latitude aspects too by using the total sum of the florida airports latitude divided by the number of airports for centre of latitude to revealing the mean centre of latitude.Thus, this code uses both mc_x and mc_y show the mean centre of florida airports under the considaetion of its measuresument for both longitude and Latitude. e)The code orders R to plot and draw the point of mean centre of longitude, where mc_x is the x-coordinates of the points and mc_y: the y-coordinates of the points. uses plotting character with a filled square size 2, then colouring it into blue. f)The code orders R to calculate and show the weighted mean centre longitude and latitude of florida airports. By doing so, it requires to first do multiplication; multiplies each longitude by its corresponding elevation, giving greater influence to airports with higher elevations. In this case, using longitude or latitude;dividing the weighted sum by the total weight gives the weighted average longitude. Then result with na.rm equals to TRUE in ordering R to ignore missing values when calculating the sums up. g)The code orders R adds points to the current graph in plotting points the serves weighted mean centre of latitude awith a filled square size 2, and colour in red. e)The code orders R to create the legend in the topright corner, and then labels it with “Mean centre” and “Weighted mean centre” in presneting it clearer to what blue and red coloured square symbols means and serve in the diagram. colours the first square blue to tell mean centre and the second square red to tell weighted mean centre.

Question 10: What do the mean and weighted mean center tell you about the distribution of the aviation facilities in Florida and their elevation? Please explain. (3 marks)

Type your response here: > summary(FL_airports$ELEV) Min. 1st Qu. Median Mean 3rd Qu. Max. 3.00 23.00 65.00 73.93 102.00 295.00 The mean center shows the average geographic location of all aviation facilities in Florida, while the weighted mean center is calculated using elevation as the weight, is located relatively northern, centre and upper to the center of the map. This means that the airports in Florida is experiencing more inland and in northern Florida that has a weighted center in that direction. Having that, the mean elevation is 73.93, which is higher or greater than the median of 65; resulting most aviation facilities are located at low elevations, but the higher-elevation airports are geographically packed that made the chart shift the weighted mean center northwest centered of the overall mean center.

Part 3C. Create and Visualize Subsets

Create Subsets

There are different elevation restrictions for airplanes. Do they have the same mean centre? Imagine we are interested in how the distribution of elevation with sm_elev (airport elevation less than the median) differ from those with lrg_elev (airport elevation greater than or equal to the median). To do this, we will split the Florida aviation facilities dataset into two subsets. One subset will only contain elevation using sm_elev as the primary source and the other will contain only those with lrg_elev as the primary source.

#TODO:find the median using the summary function
summary(FL_airports$ELEV)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3.00   23.00   65.00   73.93  102.00  295.00
lrg_elev <- subset(FL_airports, (FL_airports$ELEV <65)) 
median_elev <- median(FL_airports$ELEV, na.rm = TRUE)
sm_elev <- subset(FL_airports, ELEV < median_elev)
lrg_elev <- subset(FL_airports, ELEV >= median_elev)

Once created, the subset can be viewed in the Console by calling the object (sm_elev) using View(sm_elev). If you want to know the number of sm_elev, you can run: nrow(sm_elev[1]).

Visualize Subsets

Question 11: Show the Florida airports scatter plot using the subset data that you created. Use a different color for the subsets. Also plot the mean centres for the subsets. Be sure to include a legend, axis titles (with units), and a main title. Include your name and student number in brackets at the end of your main title. Do not show irrelevant information on the graph. Please also type your code in the code chunk below. (10 marks)

#TODO
FL_airports <- aviationfacilities_fl[aviationfacilities_fl$SITE_TYPE_CODE == "A",]
plot(FL_airports$LONG_DECIMAL, FL_airports$LAT_DECIMAL, xlab="Longitude", ylab="Latitude", main = "Airports in Florida, (SeanLim1011752051)", xlim=c(-88, -80), ylim=c(24, 33))

points(sm_elev$LONG_DECIMAL, sm_elev$LAT_DECIMAL, pch = 20, col = "green")

points(lrg_elev$LONG_DECIMAL, lrg_elev$LAT_DECIMAL, pch = 20, col = "yellow")

n<-nrow(FL_airports[1])
mc_x<-sum(FL_airports$LONG_DECIMAL)/n
mc_y<-sum(FL_airports$LAT_DECIMAL)/n
points(mc_x,mc_y,'p',pch=15,cex=2,col="blue")
mc_x<-sum(sm_elev$LONG_DECIMAL)/n
mc_y<-sum(sm_elev$LAT_DECIMAL)/n
points(mc_x,mc_y,'p',pch=15,cex=2,col="yellow")
legend("bottom", legend = c("Mean centre", "Low Elevation", "High Elevation"), pch = c(15,15), col = c("blue","green","yellow"))

Part 3D. Dispersion of Subsets

Standard Deviation of Subsets

So far, we have measured the central tendency of the spatial data. How about dispersion? Standard deviation is a measure of dispersion that can be used to assess the distribution of spatial data. To calculate the orthogonal dispersion (east-west, north-south) associated with Florida airports dataset, we will use sd() command applied on Longitude and Latitude, respectively. Please do the same for the two elevation subsets in Question 12.

sd(FL_airports$LONG_DECIMAL)
## [1] 1.785058
sd(FL_airports$LAT_DECIMAL)
## [1] 1.542124

Question 12: Please show your code as well as the calculated standard deviation in your R Markdown. Provide a concise conclusion regarding the orthogonal dispersion for the Florida aviation facilities dataset and subsets. These conclusions should include a short description of the dispersion and a comparison (i.e. Florida airports vs. sm_elev vs. lrg_elev). Remember to include units of measurement in your response. (6 marks)

Type your response here: The orthogonal dispersion for the Florida aviation facilities dataset and subsets measures where airport locations and spreads around the mean centre using the standard deviation of longitude and latitude values. A higher standard deviation indicates that airports are more widely dispersed, while a lower standard deviation indicates that airports are more packed together compare to higher standard deviation. Overall airports, the diagram shows that there is a level of spatial dispersion across the Florida. Yet, the diagram shows that representing the spread in the eastern-west Florida is mostly longitude and northern-south Florida is mostly latitude. Herein, the sm_elev has a longitude standard deviation of 1.343617 and a latitude standard deviation of 1.533126. This shows that that the lower-elevation airports are more dispersed in the northern–south Florida than in the east–west Florida The lrg_elev subset has a longitude standard deviation of 1.872165 and a latitude standard deviation of 1.157420. This shows that higher-elevation airports are more dispersed eastern–west but are more concentrated northern–south compared with the sm_elev dataset. It is then obvious that, the two elevation sets show different spatial dispersion patterns and locations within Florida. Compared with the complete Florida airports dataset, the sm_elev and lrg_elev subsets have different distributions rather than being evenly and collectivly spread in the same direction or focus in Florida state. The lrg_elev airports show greater east and west dispersion, while the sm_elev airports show greater north and south dispersion. These differences of how data is not evenly nor directional align suggest that airport elevation is related to variations that vary the actual geographic distribution of aviation facilities across Florida state.

sd(sm_elev$LONG_DECIMAL)
## [1] 1.343617
sd(sm_elev$LAT_DECIMAL)
## [1] 1.533126
sd(lrg_elev$LONG_DECIMAL)
## [1] 1.872165
sd(lrg_elev$LAT_DECIMAL)
## [1] 1.15742