zdifference_nominal: z-difference for nominal variables.

Description Usage Arguments Value Author(s) Examples

View source: R/zdifference_nominal.R

Description

The function calculates the nominal weighted z-Difference for a binary reference variable (ref) and a nominal variable (x)

Usage

1
zdifference_nominal(x,ref,w=NULL,na.rm=TRUE,norma=TRUE,r=2)

Arguments

x

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

ref

The binary reference variable as a vector.

w

The weights to calculate the weighted continuous z-Difference

na.rm

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

norma

If norma = TRUE the weighted z-Difference has a standard Gaussian distribution. If norma = FALSE the resulting distribution is chi squared with #status -1 as degree of freedom.

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#generate data. The weights are taken from uniform distribution and the
#values of x are generated from a multinomial distribution with success
#rate (0.2,0.2,0.3,0.15,0.15) for the five different status.The reference
#variable is chosen from a bernoulli distribution with success rate 0.8.
ref<-sample(1:0,1000,replace=TRUE,prob=c(0.2,0.8))
erg<-unlist(lapply(1:1000,function(z){
  w<-runif(1000)
  x<-sample(0:4,1000,replace=TRUE,prob=c(0.2,0.2,0.3,0.15,0.15))
  zdifference_nominal(x,ref,w,norma=TRUE)
}))
hist(erg,breaks=50,main="z-difference for nominal data")
plot(seq(0.005,0.97,0.01),quantile(erg,seq(0.005,0.97,0.01)),type="l",lwd=3)
points(seq(0.005,0.97,0.01),qnorm(seq(0.005,0.97,0.01)),col="red",type="l",lwd=2,lty="dashed")

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