use Supplementary for the code [🇷 for BE/BA]

posted by mittyri – Russia, 2021-12-22 21:34 (188 d 19:06 ago) – Posting: # 22710
Views: 781

Hi Weidson,

» I would like to understand why the code bellow is not working.
There are 2 problems:
- the code in the paper cannot work due to different quotation marks used (left and right), they should be substituted to simple quotations (" or ')
- there are some parts of the code not presented in the paper

So the best way is to use supplementary material as suggested
Below you can find R code from there. Note that the article is old, so some ggplot2 functions are deprecated, but still working.

library(nlme)
#head(Theoph)

#Figure 1(d)
ggplot(data=Theoph, aes(x=Time, y=conc, group=Subject)) + 
geom_line() +
labs(x="Time (hr)", y="Concentration (mg/L)")


##################################################################################
## we need some data manipulation for Figure 1(e) and Figure (f)
## below code is how to calculate approximate ntpd (nominal post time dose)
## "ntpd" is used for summarizing conc data (calculate mean at each time point)
## create body weight category for <70 kg or >=70 kg
##################################################################################

#--create a cut (time intervals)
Theoph$cut <- cut(Theoph$Time, breaks=c(-0.1,0,1,1.5, 2,3,4,6,8,12,16,20,24))

#--make sure each time point has reasonable data
table(Theoph$cut)

#--calcuate approximate ntpd
library(plyr)
tab <- ddply(Theoph, .(cut), summarize, ntpd=round(mean(Time, na.rm=T),2))

#--merge ntpd into Theoph data
Theoph <- merge(Theoph, tab, by=c("cut"), all.x=T)

#--sort the data by Subject and Time, select only nessesary columns
Theoph <- Theoph[order(Theoph$Subject, Theoph$Time),c("Subject","Wt","Dose","Time","conc","ntpd")] #head(Theoph)

#--create body weight category for <70 kg or >=70 kg for Figure 1(f)
Theoph$WT <- ifelse(Theoph$Wt<70, "WT < 70kg", "WT >= 70kg")

#--end of data manipulation
##################################################################################

# Figure 1(e)
ggplot(data=Theoph, aes(x=Time, y=conc, group=Subject)) + 
geom_line() +
labs(x="Time (hr)", y="Concentration (mg/L)") +
stat_summary(fun.y = mean, geom = "line", aes(x=ntpd, group = 1),
                color = "red", size = 1)

#--save as a ggplot object "p"
p <- ggplot(data=Theoph, aes(x=Time, y=conc, group=Subject)) + 
geom_line() +
labs(x="Time (hr)", y="Concentration (mg/L)") +
stat_summary(fun.y = mean, geom = "line", aes(x=ntpd, group = 1),
                color = "red", size = 1)

print(p) 

# Figure 1(f)
p + facet_grid(.~WT)

plot1 <- p + facet_grid(.~WT) #save for later use (section "Multiple Plots on One Page")


Kind regards,
Mittyri

Complete thread:

UA Flag
Activity
 Admin contact
22,181 posts in 4,647 threads, 1,572 registered users;
online 6 (0 registered, 6 guests [including 3 identified bots]).
Forum time: Wednesday 17:40 CEST (Europe/Vienna)

Nerds don’t just happen to dress informally.
They do it too consistently.
Consciously or not, they dress informally
as a prophylactic measure against stupidity.    Paul Graham

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5