This is a worksheet for use with Lecture 2.
You should have installed R and RStudio on your own machine (see course manual) or on the PCs in either the common room or the postgrad. teaching room.
You have a video of me narrating these slides.
If you answer correctly the colour of the box will change when correct!
Use the example code to make a smaller dataframe.
Look back to slide 8
How would you rename 'tailnum' into 'tail_number' in the flights database via using the rename(data, newvar = oldvar) method?
Did you leave additional spaces? Did you assign the dataframe correctly ('flights<-')?
Starting from R 4.1.0, base R now also has its own pipe: |> . Read more here
How would the code have looked liked if we hadn't used the pipe (%>%)?
My answer:
What is an alternative name - for the curve in the figure?
My answer:
Use the information from the previous slides to work this out.
Look back over the previous slides. Remember that you have air_time in the dataframe. Remember you can look at 'help' to find out more!
Use the help function to find out more about geom_smooth.
Which method is used in the figure?
My answer:
Do you see 'method = ' specified? What happens when it is not specified? How many rows are there in 'flights_jfk_new'
Use the information from the previous slides to work this out.
Look back over the previous slides. Remember that you need to filter our the data based on the origin - use the filter function. Next, implement the steps from the previous slides.
Find out more about shapes here
If I wanted a blue rectangle, I would use shape=
I might not have been very clear here. When you don't specify it ggplot2, will pick the number of bins.
What is the default when binwidth is left unspecified?
bins
What are the units used on the X-axis?
My answer:
Try not to peek at the solution :).
Have a look at the ggplot2 manual via the help (or use google!)
If I set as an option: dpi='print', what would be the resolution?
dpi
What does '14' in theme_stata() refer to?
My answer:
If there were missings in the 'jfk_delta$delay_no_miss' variable, what would have been the output?
My answer:
Can you complete the statement below about medians?
The median is always:
My answer:
Suppose I wanted an 89% confidence interval, then I would put the following within the brackets of the boot.ci command?
My answer:
Have a look at the boot.ci command in the help function. Find out what commands it is using. Can you work out from the default command and the output on slide 67, which value to input?
You have the example on Slide 63.
You need to replace the dependent variable! (so the bit that goes before ~ )
Thanks to Lisa DeBruine for the webexercises package. Please see general disclaimer.
sessionInfo()
## R version 4.4.2 (2024-10-31)
## Platform: aarch64-apple-darwin20
## Running under: macOS Sequoia 15.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/London
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
## [5] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
## [9] ggplot2_3.5.1 tidyverse_2.0.0 webexercises_1.1.0
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 jsonlite_1.8.9 compiler_4.4.2 tidyselect_1.2.1
## [5] nycflights13_1.0.2 jquerylib_0.1.4 scales_1.3.0 yaml_2.3.10
## [9] fastmap_1.2.0 R6_2.5.1 generics_0.1.3 knitr_1.49
## [13] munsell_0.5.1 bslib_0.8.0 pillar_1.9.0 tzdb_0.4.0
## [17] rlang_1.1.4 utf8_1.2.4 stringi_1.8.4 cachem_1.1.0
## [21] xfun_0.49 sass_0.4.9 timechange_0.3.0 cli_3.6.3
## [25] withr_3.0.2 magrittr_2.0.3 digest_0.6.37 grid_4.4.2
## [29] rstudioapi_0.17.1 hms_1.1.3 lifecycle_1.0.4 vctrs_0.6.5
## [33] evaluate_1.0.1 glue_1.8.0 fansi_1.0.6 colorspace_2.1-1
## [37] rmarkdown_2.28 tools_4.4.2 pkgconfig_2.0.3 htmltools_0.5.8.1