# geometric: Geometric (Truncated and Untruncated) Distributions In VGAM: Vector Generalized Linear and Additive Models

## Description

Maximum likelihood estimation for the geometric and truncated geometric distributions.

## Usage

 ```1 2 3 4 5``` ```geometric(link = "logitlink", expected = TRUE, imethod = 1, iprob = NULL, zero = NULL) truncgeometric(upper.limit = Inf, link = "logitlink", expected = TRUE, imethod = 1, iprob = NULL, zero = NULL) ```

## Arguments

 `link` Parameter link function applied to the probability parameter prob, which lies in the unit interval. See `Links` for more choices. `expected` Logical. Fisher scoring is used if `expected = TRUE`, else Newton-Raphson. `iprob, imethod, zero` See `CommonVGAMffArguments` for details. `upper.limit` Numeric. Upper values. As a vector, it is recycled across responses first. The default value means both family functions should give the same result.

## Details

A random variable Y has a 1-parameter geometric distribution if P(Y=y) = prob * (1-prob)^y for y=0,1,2,.... Here, prob is the probability of success, and Y is the number of (independent) trials that are fails until a success occurs. Thus the response Y should be a non-negative integer. The mean of Y is E(Y) = (1-prob)/prob and its variance is Var(Y) = (1-prob)/prob^2. The geometric distribution is a special case of the negative binomial distribution (see `negbinomial`). The geometric distribution is also a special case of the Borel distribution, which is a Lagrangian distribution. If Y has a geometric distribution with parameter prob then Y+1 has a positive-geometric distribution with the same parameter. Multiple responses are permitted.

For `truncgeometric()`, the (upper) truncated geometric distribution can have response integer values from 0 to `upper.limit`. It has density `prob * (1 - prob)^y / [1-(1-prob)^(1+upper.limit)]`.

For a generalized truncated geometric distribution with integer values L to U, say, subtract L from the response and feed in U-L as the upper limit.

## Value

An object of class `"vglmff"` (see `vglmff-class`). The object is used by modelling functions such as `vglm`, and `vgam`.

## Author(s)

T. W. Yee. Help from Viet Hoang Quoc is gratefully acknowledged.

## References

Forbes, C., Evans, M., Hastings, N. and Peacock, B. (2011). Statistical Distributions, Hoboken, NJ, USA: John Wiley and Sons, Fourth edition.

`negbinomial`, `Geometric`, `betageometric`, `expgeometric`, `zageometric`, `zigeometric`, `rbetageom`, `simulate.vlm`.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29``` ```gdata <- data.frame(x2 = runif(nn <- 1000) - 0.5) gdata <- transform(gdata, x3 = runif(nn) - 0.5, x4 = runif(nn) - 0.5) gdata <- transform(gdata, eta = -1.0 - 1.0 * x2 + 2.0 * x3) gdata <- transform(gdata, prob = logitlink(eta, inverse = TRUE)) gdata <- transform(gdata, y1 = rgeom(nn, prob)) with(gdata, table(y1)) fit1 <- vglm(y1 ~ x2 + x3 + x4, geometric, data = gdata, trace = TRUE) coef(fit1, matrix = TRUE) summary(fit1) # Truncated geometric (between 0 and upper.limit) upper.limit <- 5 tdata <- subset(gdata, y1 <= upper.limit) nrow(tdata) # Less than nn fit2 <- vglm(y1 ~ x2 + x3 + x4, truncgeometric(upper.limit), data = tdata, trace = TRUE) coef(fit2, matrix = TRUE) # Generalized truncated geometric (between lower.limit and upper.limit) lower.limit <- 1 upper.limit <- 8 gtdata <- subset(gdata, lower.limit <= y1 & y1 <= upper.limit) with(gtdata, table(y1)) nrow(gtdata) # Less than nn fit3 <- vglm(y1 - lower.limit ~ x2 + x3 + x4, truncgeometric(upper.limit - lower.limit), data = gtdata, trace = TRUE) coef(fit3, matrix = TRUE) ```

### Example output

```Loading required package: stats4
y1
0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19
304 191 143  88  60  38  38  23  25  17  13   9   8   8   3   2   5   7   2   3
20  21  23  24  25  26  27  40  41
3   2   1   2   1   1   1   1   1
VGLM    linear loop  1 :  loglikelihood = -2130.4412
VGLM    linear loop  2 :  loglikelihood = -2117.4374
VGLM    linear loop  3 :  loglikelihood = -2117.2995
VGLM    linear loop  4 :  loglikelihood = -2117.2994
VGLM    linear loop  5 :  loglikelihood = -2117.2994
(Intercept)      -0.9353602
x2               -0.9566937
x3                1.9570036
x4                0.1055838

Call:
vglm(formula = y1 ~ x2 + x3 + x4, family = geometric, data = gdata,
trace = TRUE)

Pearson residuals:
Min      1Q Median     3Q    Max
logitlink(prob) -6.285 -0.3694 0.3222 0.7341 0.9436

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.93536    0.03833 -24.406  < 2e-16 ***
x2          -0.95669    0.13344  -7.169 7.54e-13 ***
x3           1.95700    0.13206  14.819  < 2e-16 ***
x4           0.10558    0.12984   0.813    0.416
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log-likelihood: -2117.299 on 996 degrees of freedom

Number of Fisher scoring iterations: 5

No Hauck-Donner effect found in any of the estimates

 824
VGLM    linear loop  1 :  loglikelihood = -1275.3858
VGLM    linear loop  2 :  loglikelihood = -1275.1705
VGLM    linear loop  3 :  loglikelihood = -1275.1692
VGLM    linear loop  4 :  loglikelihood = -1275.1691
VGLM    linear loop  5 :  loglikelihood = -1275.1691
(Intercept)      -0.8343639
x2               -0.9769513
x3                1.7217270
x4                0.2230399
y1
1   2   3   4   5   6   7   8
191 143  88  60  38  38  23  25
 606
VGLM    linear loop  1 :  loglikelihood = -1081.6037
VGLM    linear loop  2 :  loglikelihood = -1081.171
VGLM    linear loop  3 :  loglikelihood = -1081.1596
VGLM    linear loop  4 :  loglikelihood = -1081.1593
VGLM    linear loop  5 :  loglikelihood = -1081.1593
VGLM    linear loop  6 :  loglikelihood = -1081.1593