rig {mgcv} | R Documentation |
Generates inverse Gaussian random deviates.
rig(n,mean,scale)
n |
the number of deviates required. If this has length > 1 then the length is taken as the number of deviates required. |
mean |
vector of mean values. |
scale |
vector of scale parameter values (lambda, see below) |
If x if the returned vector, then E(x) = mean
while var(x) = scale*mean^3
. For density and distribution functions
see the statmod
package. The algorithm used is Algorithm 5.7 of Gentle (2003), based on Michael et al. (1976). Note that scale
here is the scale parameter in the GLM sense, which is the reciprocal of the usual ‘lambda’ parameter.
A vector of inverse Gaussian random deviates.
Simon N. Wood simon.wood@r-project.org
Gentle, J.E. (2003) Random Number Generation and Monte Carlo Methods (2nd ed.) Springer.
Michael, J.R., W.R. Schucany & R.W. Hass (1976) Generating random variates using transformations with multiple roots. The American Statistician 30, 88-90.
http://www.maths.bath.ac.uk/~sw283/
set.seed(7) ## An inverse.gaussian GAM example, by modify `gamSim' output... dat <- gamSim(1,n=400,dist="normal",scale=1) dat$f <- dat$f/4 ## true linear predictor Ey <- exp(dat$f);scale <- .5 ## mean and GLM scale parameter ## Note that `shape' and `scale' in `rgamma' are almost ## opposite terminology to that used with GLM/GAM... dat$y <- rig(Ey,mean=Ey,scale=.2) big <- gam(y~ s(x0)+ s(x1)+s(x2)+s(x3),family=inverse.gaussian(link=log), data=dat,method="REML") plot(big,pages=1) gam.check(big) summary(big)