Can we solve for lambda in R? Assuming a poisson distribution, is there a way to solve for lambda in R?
My inputs would be "x", and Pr(X<=x) ... and I would like R to tell me the lambda.
Thanks
 A: If you have $Pr(X \leq x)$ then you have evaluations of cumulative mass function. The solution is simply a matter of curve fitting at that point.  Here is some R code to do so

set.seed(0)
mystery_lambda = rgamma(1, 5, 2)

# What you start with
x = 0:10
cumulative_mass = ppois(x, mystery_lambda)

target = function(log_lam){
  # Lambda is constrained to be positive
  # so we optimize over log lambda which us unconstrained
  # and then apply exp to make it positive.
  # Standard truck
  target_cum_mass = ppois(x, exp(log_lam))
  
  mean((cumulative_mass - target_cum_mass)^2)
}


results = optim(0, target, method = 'BFGS')

estimated_lambda = exp(results$par)

print(estimated_lambda)
[1] 3.788946

print(mystery_lambda)
[1] 3.788947

```

A: Is this what you're asking?
Suppose you are given $x = 7$ and $P(X \le 7) = 0.8666283,$ and that $X$ has a Poisson distribution, but you are not given that $\lambda = 5.$ As follows:
p = ppois(7, 5); p
[1] 0.8666283

Then a grid search in R can retrieve $\lambda = 5$ with the desired
accuracy.
lam = seq(.5, 20, by=.001)
pp = ppois(7, lam)
d = abs(p - pp)
mean(lam[d==min(d)])  # 'mean' in case of multiple hits
[1] 5

Addendum: Of course, @whuber's method, using
a related gamma distribution, is preferable
to a grid search for this problem (see comment). But such
identities are not always available for 'reconstructing' a parameter.
Here is an additional example using a grid
search for unknown binomial $n.$ Suppose
you know that $P(X \le 7) = 0.5618218$ for binomial $X$ with $p = 0.6,$ but don't know
$n = 12,$ as below in R:
p = pbinom(7, 12, .6);  p
[1] 0.5618218

Then you can retrieve $n$ as follows:
n = 2:50
pp = pbinom(7, n, .6)
d = abs(p-pp)
n[d==min(d)]
[1] 12

A: As noted by @whuber in the comments, if the task is to find $\lambda$ for a given value of $P(X\le x)$ assuming that $X\sim \operatorname{Poisson}(\lambda)$ this can be computed via the built-in gamma distribution quantile function (the inverse of the cdf) as follows.
Note first that $X$ can be seen as then number of occurrences on the interval $(0,1]$ in a Poisson process with intensity $\lambda$.  The event $X\le x$ is then equivalent to the event that the $(x+1)$'th gamma distributed arrival time $T_{x+1}>1$.  Hence,
$$
P(X\le x)=P(T_{x+1}>1)=1-F_{\lambda,x+1}(1) \tag{1}
$$
where $F_{\lambda,\alpha}$ is the cdf of the gamma distribution with rate parameter $\lambda$ and shape parameter $\alpha$.
In general the cdfs of gamma distributions with rate parameters $\lambda$ and 1 are related via
$$
F_{\lambda,\alpha}(t)=F_{1,\alpha}(\lambda t). \tag{2}
$$
Hence, combining (1) and (2), and solving for $\lambda$ we obtain
$$
\lambda = F_{1,x+1}^{-1}(1-P(X\le x))
$$
that is, qgamma(1 - 0.8666283, rate = 1, shape = 7 + 1) given that $x=7$ and $P(X\le x)=0.8666283$.
