Fitting a truncated binomial distribution to data in R

408 views Asked by At

I have discrete count data indicating the number of successes in 10 binomial trials for a pilot sample of 46 cases. (Larger samples will follow once I have the analysis set up.) The zero class (no successes in 10 trials) is missing, i.e. each datum is an integer value between 1 and 10 inclusive. I want to fit a truncated binomial distribution with no zero class, in order to estimate the underlying probability p. I can do this adequately on an Excel spreadsheet using least squares with Solver, but because I want to calculate bootstrap confidence intervals on p, I am trying to implement it in R.

Frankly, I am struggling to understand how to code this. This is what I have so far:

d <- detections.data$x

# load required packages
library(fitdistrplus)
library(truncdist)
library(mc2d)

ptruncated.binom <- function(q, p) {
  ptrunc(q, "binom", a = 1, b = Inf, p)
}
dtruncated.binom <- function(x, p) {
  dtrunc(x, "binom", a = 1, b = Inf, p)
}

fit.tbin <- fitdist(d, "truncated.binom", method="mle", start=list(p=0.1))

I have had lots of error messages which I have solved by guesswork, but the latest one has me stumped and I suspect I am totally misunderstanding something.

Error in checkparamlist(arg_startfix$start.arg, arg_startfix$fix.arg, : 'start' must specify names which are arguments to 'distr'.<

I think this means I must specify starting values for x in dtrunc and q in ptrunc, but I am really unclear what they should be.

Any help would be very gratefully received.

0

There are 0 answers