# NOT RUN {
library(magrittr)
library(dplyr)
library(csv)
library(nlme)
x <- Theoph
# mixed effects model
m1 <- nlme(
conc ~ SSfol(Dose, Time, lKe, lKa, lCl),
data = x,
fixed = lKe + lKa + lCl ~ 1,
random = lKe + lKa + lCl ~ 1
)
# some numeric and categorical properties
x %<>% mutate(arm = ifelse(as.numeric(as.character(Subject)) %% 2 == 0, 1, 2))
x %<>% mutate(site = ifelse(as.numeric(as.character(Subject)) < 7, 1, 2))
x %<>% mutate(pred = predict(m1,level = 0))
x %<>% mutate(ipred = predict(m1))
x %<>% mutate(res = residuals(m1))
x %<>% mutate(sres = residuals(m1, type = 'pearson'))
r <- ranef(m1)
r$Subject <- rownames(r)
x %<>% left_join(r)
# metadata
attr(x$Subject,'label') <- 'subject identifier'
attr(x$Wt,'label') <- 'subject weight'
attr(x$Dose,'label') <- 'theophylline dose'
attr(x$Time,'label') <- 'time since dose administration'
attr(x$conc,'label') <- 'theophylline concentration'
attr(x$arm,'label') <- 'trial arm'
attr(x$site,'label') <- 'investigational site'
attr(x$pred,'label') <- 'population-predicted concentration'
attr(x$ipred,'label') <- 'individual-predicted conentration'
attr(x$res,'label') <- 'residuals'
attr(x$sres,'label') <- 'standardized residuals'
attr(x$lKe,'label') <- 'natural log of elimination rate constant'
attr(x$lKa,'label') <- 'natural log of absorption rate constant'
attr(x$lCl,'label') <- 'natural log of clearance'
attr(x$Subject,'guide') <- '....'
attr(x$Wt,'guide') <- 'kg'
attr(x$Dose,'guide') <- 'mg/kg'
attr(x$Time,'guide') <- 'h'
attr(x$conc,'guide') <- 'mg/L'
attr(x$arm,'guide') <- '//1/Arm A//2/Arm B//'
attr(x$site,'guide') <- '//1/Site 1//2/Site 2//'
attr(x$pred,'guide') <- 'mg/L'
attr(x$ipred,'guide') <- 'mg/L'
x %>% unpack %>% as.csv('theoph.csv')
# }
# NOT RUN {
library(magrittr)
library(dplyr)
library(csv)
x <- as.csv(system.file(package = 'metaplot', 'extdata/theoph.csv'))
x %<>% pack
# sample plots
x %>% metaplot(conc)
#x %>% metaplot(site)
x %>% metaplot(Wt, arm)
x %>% metaplot(arm, Wt)
x %>% metaplot(conc, Time)
#x %>% metaplot(arm, site)
x %>% metaplot(conc, Time, Subject)
x %>% metaplot(conc, Time, , Subject)
x %>% metaplot(conc, Time, Subject, site)
x %>% metaplot(conc, Time, Subject, site, arm)
x %>% metaplot(lKe, lKa, lCl)
x %>% metaplot(conc, ipred, Time)
x %>% metaplot(conc, ipred, Time, Subject)
x %>% metaplot(conc, ipred, Time, site, arm)
x %>% metaplot(res, conc, yref = 0, ysmooth = T, conf = T, grid = T, loc = 1)
x %>% metaplot(conc, Time, panel = panel.smoothScatter)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab