search for: dpois

Displaying 20 results from an estimated 133 matches for "dpois".

Did you mean: rpois
2011 Nov 14
7
Very simple loop
I'm very new to R and am trying to create my first loop. I have: x <-c(0:200) A <- dpois(x,exp(4.5355343)) B <- dpois(x,exp(4.5355343 + 0.0118638)) C <- dpois(x,exp(4.5355343 -0.0234615)) D <- dpois(x,exp(4.5355343 + 0.0316557)) E <- dpois(x,exp(4.5355343 + 0.0004716)) F <- dpois(x,exp(4.5355343 + 0.056437)) G <- dpois(x,exp(4.5355343 + 0.1225822)) and would like to...
2018 May 31
3
Understanding the sequence of events when calling the R dpois function
Hello all, I am trying to get a better understanding of the underlying code for the stats::dpois function in R and, specifically, what happens under the hood when it is called. I finally managed to track down the C course at: https://github.com/wch/r-source/blob/trunk/src/nmath/dpois.c. It would seem that the dpois C function is taking a double for each of the x and lambda arguments so I am a...
2015 Nov 03
1
Fwd: Rcpp sugar dpois
Hi. Here is a piece of cpp code. It works, but I do not understand the rational for the use of "R::dpois" to call the function dpois since in the examples I have always found directly "dpois" or "Rcpp::dpois" that both do not work in my code. Could anyone be so patient to explain me why should it be like that? Thaks a lot, Enrico #include <Rcpp.h> using namespace Rcpp;...
2011 Aug 08
3
on "do.call" function
....1,.2,.3),2,2) > B [,1] [,2] [1,] 0.5 0.2 [2,] 0.1 0.3 > x <- c(.1,.2) > X <- cbind(1,x) > X x [1,] 1 0.1 [2,] 1 0.2 > > lt <- expand.grid(i=seq(1,2), y0=seq(0,2)) > lt i y0 1 1 0 2 2 0 3 1 1 4 2 1 5 1 2 6 2 2 > > fc <- function(y0,i) dpois(y0, exp(rowSums(t(X[i,])*B[,1]))) > > do.call(fc,lt) [1] 1.892179e-09 3.348160e-01 3.800543e-08 3.663470e-01 3.816797e-07 2.004237e-01 -------------------------------------------- Unfortunately, what I want to get is dpois(0, exp(rowSums(t(X[1,])*B[,1]))) = 0.1891356 dpois(0, exp(rowSums(t...
2009 Oct 27
1
Poisson dpois value is too small for double precision thus corrupts loglikelihood
Hi - I have a likelihood function that involves sums of two possions: L = a*dpois(Xi,theta1)*dpois(Yi,theta2)+b*(1-c)*a*dpois(Xi,theta1+theta3)*dpois(Yi,theta2) where a,b,c,theta1,theta2,theta3 are parameters to be estimated. (Xi,Yi) are observations. However, Xi and Yi are usually big (> 20000). This causes dpois to returns 0 depending on values of theta1, theta2 and theta3...
2011 Aug 08
1
problem in do.call function
...,.2,.3),2,2) > B [,1] [,2] [1,] 0.5 0.2 [2,] 0.1 0.3 > x <- c(.1,.2) > X <- cbind(1,x) > X x [1,] 1 0.1 [2,] 1 0.2 > > lt <- expand.grid(i=seq(1,2), y0=seq(0,2)) > lt i y0 1 1 0 2 2 0 3 1 1 4 2 1 5 1 2 6 2 2 > > fc <- function(y0,i) dpois(y0, exp(rowSums(t(X[i,])*B[,1]))) > > do.call(fc,lt) [1] 1.892179e-09 3.348160e-01 3.800543e-08 3.663470e-01 3.816797e-07 2.004237e-01 -------------------------------------------- Unfortunately, what I want to get is dpois(0, exp(rowSums(t(X[1,])*B[,1]))) = 0.1891356 dpois(0, exp(rowSums...
2000 Feb 25
1
lambda==0 in dpois() (PR#459)
The nice new log=TRUE option in dpois appears to mess up the case where lambda=0 (I was trying to calculate the likelihood of a saturated model). Because the behavior is now always to calculate the probability in terms of exp(log(prob)), there's a test for lambda<=0 which really needs to be only lambda<0. dpois(0:5,0) ou...
2009 Sep 19
1
Poisson Regression - Query
...) for 95% of the observations and positive non-integer values for the other 5%. What model would be appropriate? I'm thinking of fitting a GLM with a Poisson ~. Now, becuase it takes non-integer values, using the glm function with Poisson family issues warning messages. Warning messages: 1: In dpois(y, mu, log = TRUE) : non-integer x = 0.430783 2: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519 3: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519 4: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519 5: In dpois(y, mu, log = TRUE) : non-integer x = 0.371564 I'll appreciate...
2001 Aug 01
1
glm() with non-integer responses
A question about the inner workings of glm() and dpois(): Suppose I call glm(y ~ x, family=poisson, weights = w) where y contains NON-INTEGER (but still nonnegative) values. (a) Does glm() still correctly maximise the weighted Poisson loglikelihood ? (i.e. the function given by the same formal expression as the weighted loglikelihood of indepe...
2018 Jun 01
1
Understanding the sequence of events when calling the R dpois function
...n > On 31 May 2018, at 20:08, Greg Minshall <minshall at acm.org> wrote: > > Jason, > > as Chuck Berry (to whom, *thanks* for 'do {...} while(0)'!) suggested, > using grep, or even grep executed from find, such as > ---- > find . -type f -exec grep -H "dpois" \{\} \; | less > ---- > (executed from the root of an R source tree), is your friend. > > cheers, Greg
1999 Apr 09
7
Error in ppois function (PR#161)
Full_Name: Murray H Smith Version: 0.63.3 OS: Windows NT Submission from: (NULL) (130.216.5.57) The ppois function is displaced by -0.5. Try: > ppois(-0.5,1) [1] 0.3678794 > ppois(-0.51,1) [1] 0 > ppois(0,1) [1] 0.3678794 and > par(mfrow=c(2,1)) > x<-seq(-1,5,0.01) > plot(x,ppois(x,1),type="s",ylab="F(x)",main="Poisson CDF?") >
2010 Oct 17
2
dpois().......bizarre warning messages
Dear Masters, I have a question to submit consider the following script m<-4.95 obs<-rpois(36,m) # i generate 36 realization from a poisson(m) hist(obs,freq=F) curve(dpois(x,m),add=T,col="red") #i wish to overlay on the histogram the theorical poisson density function errors are returned saing the x vector doesn't contain integers.... really bizarre i can't give explanation (R version 2.11.1, no source codes) would u be so kind to suggest me a so...
2005 Oct 19
2
matching two plots
Hi, I have a problem about graphics. I would like to plot two graphs: a barplot and curve. Here is the code: > barplot(dpois(0:45,20),xlim=c(0,45),names=0:45) > curve(dnorm(x,20,sqrt(20)),from=0,to=45,add=T) Both graphs are drawn in the same figure, however the scale in both graphs dooes not match. For some reason the second plot is shifted to left. I think there is a problem concerning the axis scale. Thanks a l...
2005 Nov 02
5
Distribution fitting problem
I am using the MASS library function fitdistr(x, dpois, list(lambda=2)) but I get Error in optim(start, mylogfn, x = x, hessian = TRUE, ...) : Function cannot be evaluated at initial parameters In addition: There were 50 or more warnings (use warnings() to see the first 50) and all the first 50 warnings say 1: non-integer x = 1.452222 e...
2011 Sep 06
2
Generalizing call to function
...o 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.04226317870...
2011 Apr 27
3
Kolmogorov-Smirnov test
...vectorLength <- length(vectorSentence) # assume that we have a table(vectorSentence) # 1 2 3 4 5 6 7 8 9 # 512 1878 2400 2572 1875 1206 721 520 315 # Poisson parameter param <- fitdistr(vectorSentence, "poisson") # Expected density density.exp <- dpois(1:9, lambda=param[[1]][1]) # Expected frequ. frequ.exp <- dpois(1:9, lambda=param[[1]][1])*vectorLength # Construct numeric vector of data values (y = vFrequ for Kolmogorov-Smirnov Tests) vFrequ <- c() for(i in 1:length(frequ.exp)) { vFrequ <- append(vFrequ, rep(i, times=frequ.exp[i]))...
2007 Dec 06
1
suggested modification to the 'mle' documentation?
...two examples appearing below. Best Wishes, Spencer Graves ################################ x <- 0:10 y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8) # Pass data via function arguments rather than global variables ll.5 <- function(ymax=15, xhalf=6, x., y.) -sum(stats::dpois(y., lambda=ymax/(1+x./xhalf), log=TRUE)) (fit.5 <- mle(ll.5, start=list(ymax=15, xhalf=6), fixed=list(x.=x, y.=y))) ll3 <- function(lymax=log(15), lxhalf=log(6), x., y.) -sum(stats::dpois(y., lambda=exp(lymax)/(1+x./exp(lxhalf)), log=TRUE)) (fit3 <- mle(ll3, start...
2004 Mar 02
2
Problem with Integrate
...ies abundances: N ~ Pois(lam) log(lam) ~ N(mu, sigma2) The number of individuals are Poisson distributed with an abundance drawn from a log-normal distrbution. To fit this to data, I need to integrate out lam. In principle, I can do it this way: PLN1 <- function(lam, Count, mu, sigma2) { dpois(Count, exp(lam), log=F)*dnorm(LL, mu, sqrt(sigma2)) } and integrate between -Inf and Inf. For example, with mu=2, and sigma2=2.8 (which are roughly right for the data), and Count=73, I get this: > integrate(PLN1, -10, 10, Count=73, mu=2, sigma2=2.8) 0.001289726 with absolute error < 2.5e...
2011 Mar 22
1
Problem with plot histogram
...s, I'm trying to built a plot of two series of data, but thees series result "superimposed". The R-code is like this: goal <- c(125, 143, 81, 26, 2, 3) numgoal <- 0:5 lambda <- sum(goal*numgoal)/sum(goal) plot(numgoal, goal, type="h") x <- 0:5 y<-dpois(x, lambda) att<-y*380 lines(x,att, type="h", col="red") legend(x="topright", legend=c("Osservate", "Attese"), col=c("black","red"), ncol=1, lty=1, lwd=3, inset=c(0.01, 0.02), bg="white") How can I draw the two...
2011 Jan 27
3
Warning with mle
...here, I'm pretty new to the field of fitting (anything). I try to fit a distribution with mle, because my real data seems to follow a zero-inflated poisson distribution. So far, I tried a simple example to see whether I understand how to do it or not: # example count data x <- 0:10 y <- dpois(x, lambda = 1.4) # zero-inflated poisson zip <- function(x, lambda, prop) { (1 - prop)*dpois(x,0) + prop*dpois(x,lambda) } ll <- function(lambda = 2, prop = 0.9) { y.fit <- zip(x, lambda, prop) sum( (y - y.fit)^2 ) } fit <- mle(ll) So far, so good. The result gives me lambda...