From ac744d672641e1cb793e25501ba7acf6db702770 Mon Sep 17 00:00:00 2001 From: Liying000888 Date: Sat, 14 Sep 2024 20:03:49 -0700 Subject: [PATCH] https://github.com/USCbiostats/PM566/issues/76 --- Lab 3.html | 8401 +++++++++++++++++++++++++++++++++++++++++++++++++++- Lab 3.qmd | 1 + 2 files changed, 8317 insertions(+), 85 deletions(-) diff --git a/Lab 3.html b/Lab 3.html index b91f816..fed32a8 100644 --- a/Lab 3.html +++ b/Lab 3.html @@ -16,11 +16,10 @@ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} ul.task-list li input[type="checkbox"] { - width: 0.8em; - margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ - vertical-align: middle; +width: 0.8em; +margin: 0 0.8em 0.2em -1em; vertical-align: middle; } -/* CSS for syntax highlighting */ + pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } @@ -36,49 +35,8281 @@ pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code - { counter-reset: source-line 0; } +{ counter-reset: source-line 0; } pre.numberSource code > span - { position: relative; left: -4em; counter-increment: source-line; } +{ position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before - { content: counter(source-line); - position: relative; left: -1em; text-align: right; vertical-align: baseline; - border: none; display: inline-block; - -webkit-touch-callout: none; -webkit-user-select: none; - -khtml-user-select: none; -moz-user-select: none; - -ms-user-select: none; user-select: none; - padding: 0 4px; width: 4em; - } -pre.numberSource { margin-left: 3em; padding-left: 4px; } +{ content: counter(source-line); +position: relative; left: -1em; text-align: right; vertical-align: baseline; +border: none; display: inline-block; +-webkit-touch-callout: none; -webkit-user-select: none; +-khtml-user-select: none; -moz-user-select: none; +-ms-user-select: none; user-select: none; +padding: 0 4px; width: 4em; +} +pre.numberSource { margin-left: 3em; padding-left: 4px; } div.sourceCode - { } +{ } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -111,12 +8342,12 @@

Lab 3

#Question 1

download.file(
-  "https://raw.githubusercontent.com/USCbiostats/data-science-data/master/02_met/met_all.gz",
-  destfile = file.path("~", "Downloads", "met_all.gz"),
-  method   = "libcurl",
+  "https://raw.githubusercontent.com/USCbiostats/data-science-data/master/02_met/met_all.gz",
+  destfile = file.path("~", "Downloads", "met_all.gz"),
+  method   = "libcurl",
   timeout  = 60
 )
-met <- data.table::fread(file.path("~", "Downloads", "met_all.gz"))
+met <- data.table::fread(file.path("~", "Downloads", "met_all.gz"))
 met <- as.data.frame(met)

#Question 2

@@ -196,7 +8427,7 @@

Lab 3

str(met)
-
'data.frame':   2377343 obs. of  30 variables:
+
'data.frame':   2377343 obs. of  30 variables:
  $ USAFID           : int  690150 690150 690150 690150 690150 690150 690150 690150 690150 690150 ...
  $ WBAN             : int  93121 93121 93121 93121 93121 93121 93121 93121 93121 93121 ...
  $ year             : int  2019 2019 2019 2019 2019 2019 2019 2019 2019 2019 ...
@@ -208,22 +8439,22 @@ 

Lab 3

$ lon : num -116 -116 -116 -116 -116 ... $ elev : int 696 696 696 696 696 696 696 696 696 696 ... $ wind.dir : int 220 230 230 210 120 NA 320 10 320 350 ... - $ wind.dir.qc : chr "5" "5" "5" "5" ... - $ wind.type.code : chr "N" "N" "N" "N" ... + $ wind.dir.qc : chr "5" "5" "5" "5" ... + $ wind.type.code : chr "N" "N" "N" "N" ... $ wind.sp : num 5.7 8.2 6.7 5.1 2.1 0 1.5 2.1 2.6 1.5 ... - $ wind.sp.qc : chr "5" "5" "5" "5" ... + $ wind.sp.qc : chr "5" "5" "5" "5" ... $ ceiling.ht : int 22000 22000 22000 22000 22000 22000 22000 22000 22000 22000 ... $ ceiling.ht.qc : int 5 5 5 5 5 5 5 5 5 5 ... - $ ceiling.ht.method: chr "9" "9" "9" "9" ... - $ sky.cond : chr "N" "N" "N" "N" ... + $ ceiling.ht.method: chr "9" "9" "9" "9" ... + $ sky.cond : chr "N" "N" "N" "N" ... $ vis.dist : int 16093 16093 16093 16093 16093 16093 16093 16093 16093 16093 ... - $ vis.dist.qc : chr "5" "5" "5" "5" ... - $ vis.var : chr "N" "N" "N" "N" ... - $ vis.var.qc : chr "5" "5" "5" "5" ... + $ vis.dist.qc : chr "5" "5" "5" "5" ... + $ vis.var : chr "N" "N" "N" "N" ... + $ vis.var.qc : chr "5" "5" "5" "5" ... $ temp : num 37.2 35.6 34.4 33.3 32.8 31.1 29.4 28.9 27.2 26.7 ... - $ temp.qc : chr "5" "5" "5" "5" ... + $ temp.qc : chr "5" "5" "5" "5" ... $ dew.point : num 10.6 10.6 7.2 5 5 5.6 6.1 6.7 7.8 7.8 ... - $ dew.point.qc : chr "5" "5" "5" "5" ... + $ dew.point.qc : chr "5" "5" "5" "5" ... $ atm.press : num 1010 1010 1011 1012 1013 ... $ atm.press.qc : int 5 5 5 5 5 5 5 5 5 5 ... $ rh : num 19.9 21.8 18.5 16.9 17.4 ...
@@ -259,7 +8490,7 @@

Lab 3

summary(met$temp)
-
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
+
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  -40.00   19.60   23.50   23.59   27.80   56.00   60089 
summary(met$elev)
@@ -269,13 +8500,13 @@

Lab 3

summary(met$wind.sp)
-
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
+
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
    0.00    0.00    2.10    2.46    3.60   36.00   79693 
met[met$elev==9999.0, ] <- NA
 summary(met$elev)
-
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
+
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
     -13     101     252     413     400    4113     710 
met <- met[met$temp > -40, ]
@@ -379,7 +8610,7 @@ 

Lab 3

Mean :261.5 Mean : 7.245 3rd Qu.:310.0 3rd Qu.: 9.800 Max. :360.0 Max. :21.100 - NA's :237 NA's :168 + NA's :237 NA's :168 wind.sp.qc ceiling.ht ceiling.ht.qc ceiling.ht.method Length:2117 Min. : 30 Min. :5.000 Length:2117 Class :character 1st Qu.: 2591 1st Qu.:5.000 Class :character @@ -387,7 +8618,7 @@

Lab 3

Mean :15145 Mean :5.008 3rd Qu.:22000 3rd Qu.:5.000 Max. :22000 Max. :9.000 - NA's :4 + NA's :4 sky.cond vis.dist vis.dist.qc vis.var Length:2117 Min. : 0 Length:2117 Length:2117 Class :character 1st Qu.:16093 Class :character Class :character @@ -395,7 +8626,7 @@

Lab 3

Mean :15913 3rd Qu.:16093 Max. :16093 - NA's :683 + NA's :683 vis.var.qc temp temp.qc dew.point Length:2117 Min. : 1.00 Length:2117 Min. :-6.0000 Class :character 1st Qu.: 6.00 Class :character 1st Qu.: 0.0000 @@ -411,25 +8642,25 @@

Lab 3

Mean :NaN Mean :9 Mean :60.62 3rd Qu.: NA 3rd Qu.:9 3rd Qu.:61.85 Max. : NA Max. :9 Max. :70.01 - NA's :2117
+ NA's :2117
-
cor(elev$temp, elev$wind.sp, use="complete")
+
cor(elev$temp, elev$wind.sp, use="complete")
[1] -0.09373843
-
cor(elev$temp, elev$hour, use="complete")
+
cor(elev$temp, elev$hour, use="complete")
[1] 0.4397261
-
cor(elev$wind.sp, elev$day, use="complete")
+
cor(elev$wind.sp, elev$day, use="complete")
[1] 0.3643079
-
cor(elev$wind.sp, elev$hour, use="complete")
+
cor(elev$wind.sp, elev$hour, use="complete")
[1] 0.08807315
-
cor(elev$temp, elev$day, use="complete")
+
cor(elev$temp, elev$day, use="complete")
[1] -0.003857766
@@ -437,57 +8668,57 @@

Lab 3

Question 7

-
hist(met$elev, main= "Histogram of Elevation")
+
hist(met$elev, main= "Histogram of Elevation")
-

+

-
hist(met$temp,main= "Histogram of temperature")
+
hist(met$temp,main= "Histogram of temperature")
-

+

-
hist(met$wind.sp,main= "Histogram of wind speed")
+
hist(met$wind.sp,main= "Histogram of wind speed")
-

+

library(leaflet)
 leaflet(elev) %>%
-  addProviderTiles('OpenStreetMap') %>% 
+  addProviderTiles('OpenStreetMap') %>% 
   addCircles(lat=~lat,lng=~lon, opacity=1, fillOpacity=1, radius=100)
-
- +
+
library(lubridate)

-Attaching package: 'lubridate'
+Attaching package: 'lubridate'
-
The following objects are masked from 'package:base':
+
The following objects are masked from 'package:base':
 
     date, intersect, setdiff, union
-
elev$date <- with(elev, ymd_h(paste(year, month, day, hour, sep= ' ')))
+
elev$date <- with(elev, ymd_h(paste(year, month, day, hour, sep= ' ')))
 summary(elev$date)
                      Min.                    1st Qu. 
-"2019-08-01 00:00:00.0000" "2019-08-08 11:00:00.0000" 
+"2019-08-01 00:00:00.0000" "2019-08-08 11:00:00.0000" 
                     Median                       Mean 
-"2019-08-16 22:00:00.0000" "2019-08-16 14:09:56.8823" 
+"2019-08-16 22:00:00.0000" "2019-08-16 14:09:56.8823" 
                    3rd Qu.                       Max. 
-"2019-08-24 11:00:00.0000" "2019-08-31 22:00:00.0000" 
+"2019-08-24 11:00:00.0000" "2019-08-31 22:00:00.0000"
elev <- elev[order(elev$date), ]
 head(elev)
@@ -528,19 +8759,19 @@

Question 7

221701 2019-08-01 01:00:00 221702 2019-08-01 02:00:00
-
plot(elev$date,elev$temp, type = "l")
+
plot(elev$date,elev$temp, type = "l")
-

+

-
plot(elev$date,elev$wind.sp, type = "l")
+
plot(elev$date,elev$wind.sp, type = "l")
-

+

@@ -639,7 +8870,7 @@

Question 8

return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href); } // Inspect non-navigation links and adorn them if external - var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool)'); + var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool)'); for (var i=0; i