zdifference_coefvar: z-difference for the coefficient of vartiation for normal...

Description Usage Arguments Value Author(s) References Examples

View source: R/zdifference_coefvar.R

Description

The function calculates the coefficient of variation z-Difference for a binary reference variable (ref) and an ordinal variable (x)

Usage

1
zdifference_coefvar(x,ref,na.rm=TRUE,r=2)

Arguments

x

The variable for which the z-Difference should be calculated.

ref

The binary reference variable as a vector.

na.rm

Should NAs be removed or not. If NAs exists in dataset and na.rm=FALSE then an error will occure.

r

digits to round the returned value, default is 2

Value

The function returns the calculated z-Difference as a numeric value.

Author(s)

Tim Filla

References

https://pubmed.ncbi.nlm.nih.gov/23972521/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#generate the data.
#variable x has 5 different status with probability of
#beeing in status i is given by:0.1,0.2,0.3,0.3,0.1. #The reference variable
#is chosen from a bernoulli distribution with success #rate 0.8.
ref<-sample(0:1,1000,replace=TRUE,prob=c(0.2,0.8))
erg<-unlist(lapply(1:1000,function(z){
  w<-runif(1000)
  x<-rnorm(1000,25)
  zdifference_coefvar(x,ref)
}))
hist(erg,breaks=50,main="z-difference for continuous data")
plot(seq(0.005,0.97,0.01),quantile(erg,seq(0.005,0.97,0.01)),
type="l",lwd=3,xlab=c("quantile"),ylab=c("x-value"))
points(seq(0.005,0.97,0.01),qnorm(seq(0.005,0.97,0.01)),col="red",type="l",lwd=3,lty=2)
legend("topleft",legend=c("N(0,1) distribution","sample distribution"),lty=c(2,1),
lwd=c(3,3),col=c("red","black"),cex=1.3)

weightedZdiff documentation built on Aug. 18, 2020, 5:07 p.m.