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

posted by mittyri  – Russia, 2021-12-22 22:34 (1295 d 05:46 ago) – Posting: # 22710
Views: 3,778

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
23,428 posts in 4,929 threads, 1,687 registered users;
55 visitors (0 registered, 55 guests [including 16 identified bots]).
Forum time: 05:20 CEST (Europe/Vienna)

To know that we know what we know,
and to know that we do not know what we do not know,
that is true knowledge.    Nicolaus Copernicus

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