doubleStack: Stack a Value Twice by Two Covariates

View source: R/doubleStack.r

doubleStackR Documentation

Stack a Value Twice by Two Covariates

Description

Dataset will be melted by specified columsn after it will be melted by a second set of columns. This comes in handy when plotting multiple individual parameter estimates versus multiple covariates.

Usage

doubleStack(data, vars1, vars2)

Arguments

data

dataset containing all variables specified in vars1 and vars2

vars1

The first variable to stack by. For example c(WT,AGE,BMI,SEX)

vars2

The second variable to stack by after the first stack. For example c(ETA1,ETA2,ETA3)

Value

A data.frame

Examples

set.seed(1234)

myDF = data.frame(id = 1:100)
myDF$wt = with(myDF, signif(rnorm.by.id(id, 76,15)))
myDF$age = with(myDF, signif(sample.by.id(id, samples = seq(18,99))))
myDF$sex = with(myDF, sample.by.id(id, samples = c("F","M")))
myDF$CL = with(myDF, signif(rnorm.by.id(id, 10,1)))
myDF$V = with(myDF, signif(rnorm.by.id(id, 3,0.25)))
stacked.df = doubleStack(myDF, vars1 = c("CL","V"), vars2 = c("wt","age","sex"))
head(myDF)
head(stacked.df)
library(ggplot2)
ggplot(subset(stacked.df, variable != "sex"), aes(x = as.numeric(value), y = value1)) +
   geom_point() +
   stat_smooth(method = "lm", col = lin.fit.col) +
   facet_grid(variable1 ~ variable,scales = "free_y")

qPharmetra/qpToolkit documentation built on May 24, 2023, 8:52 a.m.