===== The exercise for this lab uses data from the file theoph.csv. This contains results from a study on the pharmacokinetics of theophylline, an anti-asthmatic drug. Twelve subjects were given oral doses of theophylline then serum concentrations were measured at 11 time points over the next 25 hours. The variables include the subject ID, their weight, the dose of the drug administered, the time at which samples were drawn and the concentration of the drug. =====
theoph <- read.csv("theoph.csv")
theoph$Subject <- factor(theoph$Subject)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
new_df <- select(theoph, Subject, Time, conc)
distinct_df <- select(distinct(theoph, Subject, Wt, Dose), Subject, Wt, Dose)
first_subject <- filter(theoph, Subject == levels(Subject)[1])
first_four_subjects <- filter(theoph, Subject %in% levels(Subject)[1:4])
avgerage_concentration <- theoph %>%
group_by(Subject) %>%
summarize(avg_concentration = mean(conc))
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
old_guy <- filter(first_subject, Subject == levels(Subject)[1])
old_guy %>%
filter(Subject=="1") %>%
ggplot(aes(x = Time, y = conc)) + geom_line() + ggtitle("Subject 1")
theoph %>%
select(Subject, Time, conc) %>%
ggplot(aes(x = Time, y = conc, color = Subject)) + geom_line(aes(column = Subject))
## Warning in geom_line(aes(column = Subject)): Ignoring unknown aesthetics:
## column
theoph %>%
select(Subject, Time, conc) %>%
ggplot(aes(x = Time, y = conc)) + geom_line() + facet_wrap(~ Subject)