betacon<-function(data){ ncols <- length(seq(0.1, 0.9, 0.01)) nrows <- length(seq(0.1, 1, 0.01)) mu <- matrix(seq(0.1, 0.9, 0.01), nrow = nrows, ncol = ncols, byrow = T ) theta <- matrix(seq(0.1, 1, 0.01), nrow = nrows, ncol = ncols, byrow = F) # mu and theta are now matrices # of the same dimensions : the # rows of mu are copies of the # vector (0.1, 0.11,...,0.9), and # the columns of theta are copies # of the vector (0, 0.1,...,1)'. loglik <- log(mu) * data[1] p <- mu s <- p for(i in 2:12) { p <- p * (1 - (mu + theta)/(1 + (i - 1) * theta)) s <- s + p # recursive specification of the loglik <- loglik + log(p) * data[i] # beta-geometric probabilities } p <- mu/mu - s loglik <- loglik + log(p) * data[13] # completes log-likelihood contour(mu[1,], theta[,1], t(loglik), nlevels = 200, xlab = "", ylab = "") persp(mu[1,], theta[,1], t(loglik),theta = 30, phi = 30, expand = 0.5, col = "lightblue", xlab = "mu", ylab = "theta", zlab = " ") } data <- c(29, 16, 17, 4, 3, 9, 4, 5, 1, 1, 1, 3, 7) betacon(data) wmsmoke.fit<-fit.betageo(c(0.1,0.1),data)