Last data update: 2014.03.03

R: A generic functon to plot Density of Z values from a...
ZvaluesfrommultinomPlotsR Documentation

A generic functon to plot Density of Z values from a simulation from a multinomial population using the balanced and unbalanced studies and a 3D representaion of the Z values

Description

A functon to plot Density of Z values from a simulation from a multinomial population using the balanced and unbalanced studies and a 3D representaion of the Z values. These plots are useful as visual tools for the confounding effects. The median values are indicated on these plots and these can be used as the consesus values of the effects of covariates in sample size calculations.

Usage

ZvaluesfrommultinomPlots(nsim,nobs,proposeddesign,balanceddesign,...)

Arguments

nsim

number of simulations to be done

nobs

number of multinomial observation

proposeddesign

a numeric vector with four elements indicating the design weights

balanceddesign

a numeric vector with all the four elements being one, indicating equal weights

...

other arguments

Details

This function generates saples from a given four cell multinomial populaton then uses the resulting multinomial probabilities in calculating the effect of covariates (Z values). Currently we implement a design arising from a proteomics study in which there is a binary confounder and a binary exposure. The cross-tabulation of the categories of these covariates results into a 4-cell multinomial categories.

Value

density plot

Density plot of the Z values

3D plot of Z values

3D plot of the Z values against a two dimensional subspace of the 3-D space of multinomial probabilities

Author(s)

Stephen Nyangoma

References

Nyangoma SO, Ferreira JA, Collins SI, Altman DG, Johnson PJ, and Billingham LJ: Sample size calculations for planning clinical proteomic profiling studies using mass spectrometry. (Working paper)

See Also

Also see the function f.

Examples

#density plots

nsim=10000;nobs=300;proposeddesign=c(1,2,1,7);balanceddesign=c(1,1,1,1)

f=function (x,y,z) {
Z=(1-x-z)*(x+y)/(2*(((1-x-z)*(1-x-y)*(1-y-z))-(1-x-y-z)^2))
Z
}

mul_1=rmultinom(nsim, nobs, prob = proposeddesign)/nobs
mul_1=t(mul_1)

mul_1=data.frame(mul_1)


 
names(mul_1)=c('x','y','z')


x=mul_1$x
y=mul_1$y

z=mul_1$z

# compute Z values (see Nyangoma et al. 2009)

Z=f(x,y,z)


x1=x
y1=y

z1=Z


#########################################
#####  pr=c(1,1,1,1)# balanced design
#########################################

mul_2=rmultinom(nsim, nobs, prob = balanceddesign)/nobs
mul_2=t(mul_2)


mul_2=data.frame(mul_2) 
names(mul_2)=c('x','y','z')

x=mul_2$x
y=mul_2$y

z=mul_2$z

Zb=f(x,y,z)

x2=x
y2=y

z2=Zb

#####################################
#####################################
#summary(Zb)
pdf('ZvaluesDensityPlots.pdf')
densityZ=density(Z,bw=0.1)
densityZb=density(Zb,bw=0.1)

plot(density(Zb,bw=0.1),xlim=c(min(c(densityZ$x,densityZb$x)),max(c(densityZ$x,densityZb$x))),
ylim=c(min(c(densityZ$y,densityZb$y)),max(c(densityZ$y,densityZb$y))),col='blue',lwd=2,lty=1,xlab='confounding effect - Z values',main='')


lines(density(Z,bw=0.1),lwd=2,xlab='',main='')

abline(v=median(Z),lty=2,col='red')
abline(v=median(Zb),lty=2,col='green')

legend(max(c(densityZ$x,densityZb$x)) - 2, max(c(densityZ$y,densityZb$y)) - 0.2, legend=c("blanced","unblanced"), col = c("blue","black"), lty = 1)
dev.off()
####################################
####################################

library(lattice)
library(rgl)
 library(scatterplot3d)
a=c(x1,x2)
 b=c(y1,y2)
 Z1=c(z1,z2)
 
group=c(rep(1,10000),rep(2,10000))

Data=data.frame(a,b,Z=Z1,group)

Data$group=as.factor(Data$group)

Plot3D=cloud(b ~ a*Z,scales = list(arrows = FALSE), data=Data, group=group,screen = list(x = 30, y = -60),ylim=c(0,15),zlim=c(0.05,0.45),xlim=c(0,0.45))

Plot3D
nsim=10000;nobs=300;proposeddesign=c(1,2,1,7);balanceddesign=c(1,1,1,1)
ZvaluesfrommultinomPlots(nsim,nobs,proposeddesign,balanceddesign)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(clippda)
Loading required package: limma
Loading required package: statmod
Loading required package: rgl
Loading required package: lattice
Loading required package: scatterplot3d
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following object is masked from 'package:limma':

    plotMA

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: tools
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/clippda/ZvaluesfrommultinomPlots.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ZvaluesfrommultinomPlots
> ### Title: A generic functon to plot Density of Z values from a simulation
> ###   from a multinomial population using the balanced and unbalanced
> ###   studies and a 3D representaion of the Z values
> ### Aliases: ZvaluesfrommultinomPlots
> ### Keywords: generic
> 
> ### ** Examples
> 
> #density plots
> 
> nsim=10000;nobs=300;proposeddesign=c(1,2,1,7);balanceddesign=c(1,1,1,1)
> 
> f=function (x,y,z) {
+ Z=(1-x-z)*(x+y)/(2*(((1-x-z)*(1-x-y)*(1-y-z))-(1-x-y-z)^2))
+ Z
+ }
> 
> mul_1=rmultinom(nsim, nobs, prob = proposeddesign)/nobs
> mul_1=t(mul_1)
> 
> mul_1=data.frame(mul_1)
> 
> 
>  
> names(mul_1)=c('x','y','z')
> 
> 
> x=mul_1$x
> y=mul_1$y
> 
> z=mul_1$z
> 
> # compute Z values (see Nyangoma et al. 2009)
> 
> Z=f(x,y,z)
> 
> 
> x1=x
> y1=y
> 
> z1=Z
> 
> 
> #########################################
> #####  pr=c(1,1,1,1)# balanced design
> #########################################
> 
> mul_2=rmultinom(nsim, nobs, prob = balanceddesign)/nobs
> mul_2=t(mul_2)
> 
> 
> mul_2=data.frame(mul_2) 
> names(mul_2)=c('x','y','z')
> 
> x=mul_2$x
> y=mul_2$y
> 
> z=mul_2$z
> 
> Zb=f(x,y,z)
> 
> x2=x
> y2=y
> 
> z2=Zb
> 
> #####################################
> #####################################
> #summary(Zb)
> pdf('ZvaluesDensityPlots.pdf')
> densityZ=density(Z,bw=0.1)
> densityZb=density(Zb,bw=0.1)
> 
> plot(density(Zb,bw=0.1),xlim=c(min(c(densityZ$x,densityZb$x)),max(c(densityZ$x,densityZb$x))),
+ ylim=c(min(c(densityZ$y,densityZb$y)),max(c(densityZ$y,densityZb$y))),col='blue',lwd=2,lty=1,xlab='confounding effect - Z values',main='')
> 
> 
> lines(density(Z,bw=0.1),lwd=2,xlab='',main='')
> 
> abline(v=median(Z),lty=2,col='red')
> abline(v=median(Zb),lty=2,col='green')
> 
> legend(max(c(densityZ$x,densityZb$x)) - 2, max(c(densityZ$y,densityZb$y)) - 0.2, legend=c("blanced","unblanced"), col = c("blue","black"), lty = 1)
> dev.off()
png 
  2 
> ####################################
> ####################################
> 
> library(lattice)
> library(rgl)
>  library(scatterplot3d)
> a=c(x1,x2)
>  b=c(y1,y2)
>  Z1=c(z1,z2)
>  
> group=c(rep(1,10000),rep(2,10000))
> 
> Data=data.frame(a,b,Z=Z1,group)
> 
> Data$group=as.factor(Data$group)
> 
> Plot3D=cloud(b ~ a*Z,scales = list(arrows = FALSE), data=Data, group=group,screen = list(x = 30, y = -60),ylim=c(0,15),zlim=c(0.05,0.45),xlim=c(0,0.45))
> 
> Plot3D
> nsim=10000;nobs=300;proposeddesign=c(1,2,1,7);balanceddesign=c(1,1,1,1)
> ZvaluesfrommultinomPlots(nsim,nobs,proposeddesign,balanceddesign)
$Zvalue
[1] 4.035192

$varZ
[1] 0.2488115

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>