Description Usage Arguments Methods Note Examples
Given an mle2
fit and an optional list
of new data, return predictions (more generally,
summary statistics of the predicted distribution)
1 2 3 4 5 6 7 8 9 | ## S4 method for signature 'mle2'
predict(object, newdata=NULL,
location="mean", newparams=NULL, ...)
## S4 method for signature 'mle2'
simulate(object, nsim,
seed, newdata=NULL, newparams=NULL, ...)
## S4 method for signature 'mle2'
residuals(object,type=c("pearson","response"),
location="mean",...)
|
object |
an mle2 object |
newdata |
optional list of new data |
newparams |
optional vector of new parameters |
location |
name of the summary statistic to return |
nsim |
number of simulations |
seed |
random number seed |
type |
residuals type |
... |
additional arguments (for generic compatibility) |
an mle2
fit
For some models (e.g. constant models), predict
may
return a single value rather than a vector of the appropriate length.
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 30 31 32 33 34 | set.seed(1002)
lymax <- c(0,2)
lhalf <- 0
x <- runif(200)
g <- factor(rep(c("a","b"),each=100))
y <- rnbinom(200,mu=exp(lymax[g])/(1+x/exp(lhalf)),size=2)
dat <- data.frame(y,g,x)
fit3 <- mle2(y~dnbinom(mu=exp(lymax)/(1+x/exp(lhalf)),size=exp(logk)),
parameters=list(lymax~g),
start=list(lymax=0,lhalf=0,logk=0),
data=dat)
plot(y~x,col=g)
## true curves
curve(exp(0)/(1+x/exp(0)),add=TRUE)
curve(exp(2)/(1+x/exp(0)),col=2,add=TRUE)
## model predictions
xvec = seq(0,1,length=100)
lines(xvec,predict(fit3,newdata=list(g=factor(rep("a",100),levels=c("a","b")),
x = xvec)),col=1,lty=2)
lines(xvec,predict(fit3,newdata=list(g=factor(rep("b",100),levels=c("a","b")),
x = xvec)),col=2,lty=2)
## comparing automatic and manual predictions
p1 = predict(fit3)
p2A =
with(as.list(coef(fit3)),exp(`lymax.(Intercept)`)/(1+x[1:100]/exp(lhalf)))
p2B =
with(as.list(coef(fit3)),exp(`lymax.(Intercept)`+lymax.gb)/(1+x[101:200]/exp(lhalf)))
all(p1==c(p2A,p2B))
##
simulate(fit3)
|
Loading required package: stats4
[1] TRUE
[1] 0 1 0 2 1 0 0 1 0 0 0 1 1 1 2 0 0 0 0 1 1 2 0 0 0
[26] 1 0 2 0 0 0 1 2 0 1 0 1 0 2 0 1 1 2 2 0 0 0 1 0 0
[51] 0 2 1 0 0 0 1 0 0 2 1 0 1 0 0 0 0 0 0 0 0 2 2 1 0
[76] 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0
[101] 2 17 0 8 7 1 8 8 2 17 2 2 4 6 1 8 0 9 12 1 2 4 20 0 1
[126] 2 5 2 3 5 4 0 12 8 1 2 0 2 1 3 4 9 2 15 10 13 1 2 6 7
[151] 2 2 4 14 9 2 12 2 4 5 14 1 4 2 17 7 4 8 5 4 2 9 2 4 2
[176] 9 4 1 10 6 1 7 9 7 6 5 2 3 0 3 4 8 1 3 24 1 0 0 14 7
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.