Hello guys,

I would like to ask for help to understand what is going on in
"func2". My plan is to generalize "func1", so that are expected same
results in "func2" as in "func1". Executing "func1" returns...

0.25 with absolute error < 8.4e-05

But for "func2" I get...

Error in dpois(1, 0.1, 23.3065168689948, 0.000429064542600244,
3.82988398013855,  :
 unused argument(s) (0.000429064542600244, 3.82988398013855,
0.00261104515224461, 1.37999516465199, 0.0072464022020844,
0.673787740945863, 0.0148414691931943, 0.383193602946711,
0.0260964690514175, 0.236612585866545, 0.0422631787036055,
0.152456705113438, 0.0655923922306948)

Thanks in advance.

func1 <- function(y, a, rate) {
       f1 <- function(n, y, a, rate) {
               lambda <- a * n
               dexp(n, rate) * dpois(y, lambda)
       }
       integrate(f1, 0, Inf, y, a, rate)
}

func1(1, 0.1, 0.1)


func2 <- function(y, a, rate, samp) {
       f1 <- function(n, y, a, rate, samp) {

               SampDist <- function(y, a, n, samp) {
                       lambda <- a * n
                       dcom <- paste("d", samp, sep="")
                       dots <- as.list(c(y, lambda))
                       do.call(dcom, dots)
               }

               dexp(n, rate) * SampDist(y, a, n, samp)
       }
       integrate(f1, 0, Inf, y, a, rate, samp)
}

func2(1, 0.1, 0.1, "pois")

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to