个人学习笔记

  • 首页
  • NONMEM
  • PBPK
  • R语言
  • 其他
  • 常用链接
  • 博客简介
  • 隐私政策
学海无涯勤可渡,书山万仞志能攀
  1. 首页
  2. NONMEM
  3. 正文

R语言笔记:群体药动学数据探索

2023年3月10日 2305点热度 1人点赞 0条评论

用到的包

library(dplyr)
library(ggplot2)
library(gridExtra)

加载资源

source("D:\\工作文档\\R\\col_function.r")

设置工作目录

setwd("C:\\Users\\Administrator.ADMIN-20170618T\\Documents\\demo-data\\PPK\\iv infusion 3cp")

读取数据

#read data----
SDTAB<-read.table("SDTAB1",sep="",skip=1,header = TRUE) 
PKdata<-read.csv("MonkeyPK.csv",header=T,skip=2)

过滤数据

#filter data----
PKdata<-filter(MKPK,MDV==0)
PKdata<-filter(MKPK,C!="C")
INDFIT_PK5<-filter(INDFIT_PK,TIME>829)

单位和分类因子

#add unit----
MKPK$DOSE[MKPK$DOSE==0.5]<-"0.5 mg"
#data group----
MKPK$DOSE_f<-factor(MKPK$DOSE,levels=c("0.5 mg","1.5 mg"))

求均值方差等

#Conc Mean Profile-----
ConcvsTIME<-summarise(group_by(MKPKSAD,TIME,DOSE_f),
                      mean=mean(CONC),
                      sd=sd(CONC),
                      n=sum(!is.na(CONC)),
                      se=sd/sqrt(n))

#---
  ylim(0,500)+
  xlim(0,1200)+
  scale_y_log10()+
  facet_wrap(~DOSE_f,ncol=3)+
  facet_wrap(~ID,ncol=7)+
  guides(color=FALSE)+

  legend.text = element_blank()  
  legend.position="none"
  scale_y_log10(breaks=c(c(0.1,1,10,100,1000)),
              labels=c(0.1,1,10,100,1000))
  scale_x_continuous(breaks=c(c(168,336,504,672,840,1008,1176,1344,1512,1680,1848)),
  labels=c("1","2","3","4","5","6","7","8","9","10","11"))
  scale_y_continuous(limits = c(0,800),
                     breaks = seq(0,800,200))+
    scale_x_continuous(limits = c(2040,2160),
                       breaks = seq(2040,2160,24))+
    scale_colour_manual(name="",
                        breaks=c("10 mg","20 mg","40 mg","10~40 mg"),
    scale_colour_hue(labels=c("0.6 mg/kg","1.2 mg/kg","2 mg/kg","3 mg/kg","4 mg/kg","4.5 mg/kg","5.3 mg/kg","7.1 mg/kg","8 mg/kg","9 mg/kg","16 mg/kg","44.5 mg/kg"))+                       values=c("#ED0000CC","#42B540FF","#00468BCC","black")) +  

#----
CONCSADvsTIME<-
  ggplot(data=ConcvsTIME)+
  geom_point(aes(x=TIME,y=mean,group=factor(DOSE_f),color=factor(DOSE_f)))+
  geom_errorbar(aes(x=TIME,ymin=mean-se,ymax=mean+se,color=factor(DOSE_f),group=factor(DOSE_f)),width=0.5,size=0.7)+
  geom_line(aes(x=TIME,y=mean,color=factor(DOSE_f),group=factor(DOSE_f)),size=0.7)+
  labs(color="",shape="")+
  xlab("Time (h)")+ylab("绝对OD值")+
  # facet_wrap(~DOSE_f)+
  theme_test()+
  theme(axis.text=element_text(size=14,color="black"),
        # axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=14),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5))
CONCSADvsTIME
ggsave("CONCSADvsTIME.jpeg", CONCSADvsTIME, width = 6, height = 3)


#----
INDFIT_PK2<-filter(INDFIT_PK,NMT<169)
INDFIT_PK3<-filter(INDFIT_PK,NMT>839)
INDFIT_PK<-ggplot()+
  geom_line(data=INDFIT_PK2,aes(x=NMT,y=mean,color=factor(DOSE_f),group=DOSE_f),size=0.7)+
  geom_line(data=INDFIT_PK3,aes(x=NMT,y=mean,color=factor(DOSE_f),group=DOSE_f),size=0.7)+
  geom_point(data=INDFIT_PK,aes(x=NMT,y=mean,color=factor(DOSE_f)))+
  # geom_errorbar(data=INDFIT_PK,aes(x=NMT,ymin=mean-se,ymax=mean+se,color=factor(DOSE_f)),width=0.4,size=0.7)+
  labs(color="",shape="")+
  xlab("Time(h)")+ylab("Concentration (ug/mL)")+
  # xlim(0,1200)+
  # ylim(0,500)+
  # scale_shape_manual(values = c(4:10))+
  theme_test()+
  theme(axis.text=element_text(size=14,color="black"),
        axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=14),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5))
INDFIT_PK
ggsave("CONCprofile.jpeg", INDFIT_PK, width = 6, height = 4)


#----
ConcvsTIME<-filter(ConcvsTIME,TIME!=0)
CONCSADvsTIME3<-
  ggplot(data=filter(MKPKSAD,TIME!=0))+
  geom_point(aes(x=TIME,y=CONC,group=factor(ID),color=factor(DOSE_f)),size=1)+
  geom_line(aes(x=TIME,y=CONC,group=factor(ID),color=factor(DOSE_f)),size=0.5)+
  labs(color="",shape="")+
  xlab("Time (h)")+ylab("Concentration (渭g/mL)")+
  facet_wrap(~DOSE_f,ncol=3)+
  theme_test()+
  theme(axis.text=element_text(size=12,color="black"),
        # axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=12),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5),
        legend.position="none")
CONCSADvsTIME3
ggsave("CONCSADvsTIMEGROUP.jpeg", CONCSADvsTIME3, width = 6, height = 3)

#CONC----
INDFIT_PK<-EPOPKMAD1
INDFIT_PK4<-filter(INDFIT_PK,TIME<169)
INDFIT_PK5<-filter(INDFIT_PK,TIME>829)
NDFIT_PK<-ggplot()+
  geom_line(data=INDFIT_PK4,aes(x=TIME,y=CONC,group=DOSE_f,color=factor(DOSE_f)))+
  geom_line(data=INDFIT_PK5,aes(x=TIME,y=CONC,group=DOSE_f,color=factor(DOSE_f)))+
  geom_point(data=INDFIT_PK,aes(x=TIME,y=CONC,color=factor(DOSE_f)),shape=21,fill=NA)+
  facet_wrap(~ID,ncol=7)+
  xlab("\nTime after Dose (h)")+ylab("Concentration (ug/mL)\n")+
  guides(color=FALSE)+
  theme_test()+
  theme(axis.text=element_text(size=10,color="black"),
        # axis.text.y=element_text(angle = 90,hjust=0.5),
        axis.title =element_text(size=14),
        panel.border = element_rect(colour = "black", fill=NA, size=0.5),
        strip.background = element_rect(fill="lightblue",colour = NA),
        strip.text = element_text(size = 12))
NDFIT_PK
ggsave("CONCIDprofile.jpeg", NDFIT_PK, width = 14, height = 8)
标签: R语言
最后更新:2023年4月4日

MSxiaoming

得失从缘,心无增减

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复
站内搜索

MSxiaoming

得失从缘,心无增减

标签聚合
折腾 PBPK模型 NONMEN R语言 NONMEM POPPK R语言,数据管理 群体药代动力学

COPYRIGHT © 2023 个人学习笔记. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

皖ICP备2023004398号-1