Skip to content

Commit

Permalink
version 0.50-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ntzoufras authored and gaborcsardi committed Aug 25, 2005
0 parents commit b450ccc
Show file tree
Hide file tree
Showing 30 changed files with 2,434 additions and 0 deletions.
11 changes: 11 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: bivpois
Title: Bivariate Poisson Models Using The EM Algorithm
Version: 0.50-2
Date: 2005-08-25
Depends: R (>= 2.0.1)
Author: Dimitris Karlis and Ioannis Ntzoufras
Description: Functions for fitting Bivariate Poisson Models using the EM algorithm. Details can be found in Karlis and Ntzoufras (2003, RSS D & 2004,AUEB Technical Report)
Maintainer: Ioannis Ntzoufras <ntzoufras@aueb.gr>
License: GPL (version 2 or later)
URL: http://www.stat-athens.aueb.gr/~jbn/papers/paper14.htm
Packaged: Wed Aug 31 16:13:32 2005; admin
45 changes: 45 additions & 0 deletions R/bivpois.table.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"bivpois.table" <-
function(x, y, lambda = c(1, 1, 1))
{
# ------------------------------------------------------------------------------
# Karlis and Ntzoufras (2003, 2004)
# EM algorithms for Bivariate Poisson Models
# ------------------------------------------------------------------------------
# x : 1st count variable
# y : 2nd count variable
# lambda: parameters of the bivariate poisson distribution.
# ------------------------------------------------------------------------------

j<-0
n <- length(x)
maxy <- c(max(x), max(y)) #Set initial values for parameters
lambda1 <- lambda[1]
lambda2 <- lambda[2]
lambda3 <- lambda[3]
if((x == 0) | (y == 0)) {
prob <- matrix(NA, nrow = maxy[1] + 1, ncol = maxy[2]+1, byrow = T)
prob[maxy[1] + 1, maxy[2] + 1] <- exp( - lambda3) *
dpois(x[j], lambda1[j]) * dpois(y[j], lambda2[j])
}
else {
prob <- matrix(NA, nrow = maxy[1] + 1, ncol = maxy[2]+1, byrow = T)
k <- 1
m <- 1
prob[k, m] <- exp( - lambda1 - lambda2 - lambda3)
for(i in 2:(maxy[1] + 1)) {
prob[i, 1] <- (prob[i - 1, 1] * lambda1)/(i - 1)
}
for(j in 2:(maxy[2] + 1)) {
prob[1, j] <- (prob[1, j - 1] * lambda2)/(j - 1)
}
for(j in 2:(maxy[2] + 1)) {
for(i in 2:(maxy[1] + 1)) {
prob[i, j] <- (lambda1 * prob[i - 1, j] +
lambda3 * prob[i - 1, j - 1])/(i - 1)
}
}
}
result <- prob
result
}

0 comments on commit b450ccc

Please sign in to comment.