Skip to content

Instantly share code, notes, and snippets.

@AndrewLJackson
Created August 14, 2017 14:50
Show Gist options
  • Save AndrewLJackson/57f77a87625a1abacf9172a3d344cdef to your computer and use it in GitHub Desktop.
Save AndrewLJackson/57f77a87625a1abacf9172a3d344cdef to your computer and use it in GitHub Desktop.
Testing disparity::bhatt.coeff
# examples of iteration estimates
# iteration 1, model 1
it1.m1<-c(0.007439839, 0.229489378, 0.035664652, 0.015154735, 0.712251396)
# iteration 2, model 1
it2.m1<-c(0.04197685, 0.22032073, 0.05718590, 0.03484489, 0.64567163)
# iteration 1, model 2
it1.m2<-c(0.09325976, 0.29549676, 0.15327778, 0.08599277, 0.37197294)
# iteration 2, model 2
it2.m2<- c(0.06429175, 0.02222554, 0.15422684, 0.65528134, 0.10397452)
# create a data.frame to enable summaries to be calculated more easily
df <- data.frame(it1.m1, it2.m1, it1.m2, it2.m2)
# The are identical when using the bw.nrd0 bandwidth function
# two iteration comparisons with the same answer
band_width = bw.nrd0
first <- dispRity::bhatt.coeff(it1.m1,it1.m2, bw = band_width)
second <- dispRity::bhatt.coeff(it2.m1,it2.m2, bw = band_width)
# are they exactly equal?
first == second
# they are not equal if using the similar bw.nrd function
band_width = bw.nrd
first <- dispRity::bhatt.coeff(it1.m1,it1.m2, bw = band_width)
second <- dispRity::bhatt.coeff(it2.m1,it2.m2, bw = band_width)
# are they exactly equal?
first == second
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# test that bhat.coeff() works on some simulated data
x1 <- rnorm(5, 2, 1)
y1 <- rnorm(5, 0, 1)
x2 <- rnorm(5, 2, 1)
y2 <- rnorm(5, 0, 1)
# these are not equal
dispRity::bhatt.coeff(x1, y1)
dispRity::bhatt.coeff(x2, y2)
# test that it returns 1 when given identical distributions
dispRity::bhatt.coeff(x, x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment