jwindle / BayesLogit

The R Package BayesLogit
GNU General Public License v3.0
14 stars 6 forks source link

Bug (?) when dealing with integers for tilting parameters #5

Open gpapadog opened 4 years ago

gpapadog commented 4 years ago

Generating data when the tilting parameter is of class integer or numeric return different results. See the example below, where cc varies from 1 to 24 and draws from the Polya-Gamma are acquired setting z = cc and z = as.numeric(cc).

B <- 10000

x1 <- matrix(NA, nrow = B, ncol = length(z_vals))
x2 <- x1

set.seed(1234)

for (bb in 1 : B) {
  for (cc in 1 : length(z_vals)) {

    var1 <- cc
    var2 <- as.numeric(cc)

    if (var1 != var2) {
      print('var1 and var2 not the same')
    }

    x1[bb, cc] <- BayesLogit::rpg(1, h = 1, z = var1)
    x2[bb, cc] <- BayesLogit::rpg(1, h = 1, z = var2)

  }
}

par(mfrow = c(2, 3))
for (cc in 1 : length(z_vals)) {
  plot((density(x1[!is.na(x1[, cc]), cc])), main = cc)
  lines(density(x2[!is.na(x2[, cc]), cc], na.rm = TRUE), col = 'red')
}