UC San Diego
COGS 137 - Fall 2024
2024-10-04
Q: Does R let you perform arithmetic across number and integer types?
A: Yup! For example7L + 2
gives you 9. (Similarly7L + 2.2
gives 9.2)
Q: I am confused on how to open up projects, what it means to comit and pull.
A: We’ll review this again today!
Q: I am very new to using Github, so using Github is a bit confusing, but probably just b/c I am very new to it.
A: This is a normal feeling at the start of this course! I promise in a week it will feel more comfortable!
Q: I’m curious about the usage of R versus Python. Are there certain situations where R is more useful than Python?
A: In a nutshell, almost everything you can do in one you can do in the other. However, in my opinion, R is most useful when 1) cleaning data, 2) using statistical models, and 3) visualizing data. (On the flip side, when I’m writing software, using APIs, and gathering data, I typically turn to Python.)
Q: How do I save my lecture practice into a new file in R?
A: I would recommend opening a new .Rmd file and then saving it with the name of the lecture.
Q: i noticed that global variables remain in the environment panel even when i delete that variable in my rmd script. does it matter that they are still there? i tried clicking the broom and rerunning the code, and only the variables i wanted remained, but is this the right way to go about changing or deleting variables in my code?
A: Yup! The broom will clean up your environment! There is also anrm()
function if you ever want to remove an individual variable from your environment.
Q: Am I supposed to create an “R Markdown” or an “R Notebook”?
A: I’ll demo R Markdown, so encouraging use of that.
Q: Will we be covering any syntax guidelines when programming in R? For example, in other programming languages indents/spaces are necessary for many functions but I’m wondering if there is anything like that used in R.
A: I will highlight them as we go! R does not necessitate whitespace ever, but stylistically, we will encourage it. What I teach will be based off of this style guide.
Q: How many points are there in total for the extra credits
A: I’m not totally sure yet. At least a few points.
Q: I wonder what will be the format of the lab session?
A: Typically a short presentation (5 min) at the beginning to explain the lab or discuss the most difficult/confusing part. Then, time to work on lab and get questions answered by staff.
Q: Could you please post the slides one or two days before class? I would like to review them in advance so I can better follow along during the lecture and not feel lost. A: I totally understand the request, and I’ll do my best! (For example, these have been up since Monday), but I’m re-doing the slides up to class many days. While the examples will change this quarter, the concepts will overlap with last Fall, so feel free to reference those notes.
Q: What are the main parts of the R interface that we will be interacting with?
A: RMarkdown files, R Console, Git pane, Files pane, and Plots pane
Q: I had a question about the survey for participation. I’m usually busy right after class. Is there any way to get credit for it even if I submit it a couple of hours later or for it to open a little before class ends.
A: I do typically end class a few minutes early for completion then and we’re working to open it a few minutes before class ends. It’s always fine to fill it out later if it’s open. It will always be open until at least 5PM.
Due Dates:
Note:
options(download.file.method="wget")
Source: https://academic.oup.com/clinchem/article/59/3/478/5621997
Evidence suggests recent smoking and/or blood THC concentrations 2–5 ng/mL are associated with substantial driving impairment, particularly in occasional smokers.link
As of 2021…link
Various approaches:
Focus here: Can we identify a biomarker of recent use?
Which compound, in which matrix, and at what cutoff is the best biomarker of recent use?
Source: Hoffman et al.
Participants were:
Source: Fitzgerald et al.
Source: Hoffman et al.
Source: Hoffman et al.
Source: Hoffman et al.
Three matrices:
Variables:
ID
| participants identifierTreatment
| placebo, 5.90%, 13.40%Group
| Occasional user, Frequent userTimepoint
| indicator of which point in the timeline participant’s collection occurredtime.from.start
| number of minutes from consumptionYou’ll have access once your groups/repos are created…(today I want people to follow along; there will be time to try on your own soon!)
Important
These data are for our use only and not to be shared widely, so this case study cannot be put in your portfolio, but CS02 and your final project can!
Where We’re Headed…
Results from: Hubbard et al (2021) Biomarkers of Recent Cannabis Use in Blood, Oral Fluid and Breath link
…and if there’s time PPV and Accuracy post 3h
Source: Fiztgerald et al.