@@ -490,30 +490,43 @@ predict.ppm <- local({
490490 if (type == " intensity" )
491491 z <- PoisSaddle(z , fitin(model ))
492492
493- # #
494493 if (needSE ) {
495- # # extract variance-covariance matrix of parameters
496- vc <- vcov(model , new.coef = new.coef )
497- # # compute model matrix
498- fmla <- rhs.of.formula(formula(glmfit ))
494+ # # compute standard error, needed for some purpose
495+ if (inherits(glmfit , " gam" )) {
496+ # # compute SE using predict.gam
497+ if (! is.null(new.coef ))
498+ warning(" new.coef ignored in standard error calculation" )
499+ SE <- predict(glmfit , newdata = newdata , type = " response" ,
500+ se.fit = TRUE )[[2 ]]
501+ } else {
502+ # # Use vcov.ppm
503+ # # extract variance-covariance matrix of parameters
504+ vc <- vcov(model , new.coef = new.coef )
505+ # # compute model matrix
506+ fmla <- rhs.of.formula(formula(glmfit ))
499507# mf <- model.frame(fmla, newdata, ..., na.action=na.pass)
500508# mm <- model.matrix(fmla, mf, ..., na.action=na.pass)
501- mf <- model.frame(fmla , newdata , na.action = na.pass )
502- mm <- model.matrix(fmla , mf , na.action = na.pass )
503- if (nrow(mm ) != nrow(newdata ))
504- stop(" Internal error: row mismatch in SE calculation" )
505- # # compute relative variance = diagonal of quadratic form
506- if (ncol(mm ) != ncol(vc ))
507- stop(" Internal error: column mismatch in SE calculation" )
508- vv <- quadform(mm , vc )
509- # # standard error
510- SE <- lambda * sqrt(vv )
509+ mf <- model.frame(fmla , newdata , na.action = na.pass )
510+ mm <- model.matrix(fmla , mf , na.action = na.pass )
511+ if (nrow(mm ) != nrow(newdata ))
512+ stop(" Internal error: row mismatch in SE calculation" )
513+ # # compute relative variance = diagonal of quadratic form
514+ if (ncol(mm ) != ncol(vc ))
515+ stop(" Internal error: column mismatch in SE calculation" )
516+ vv <- quadform(mm , vc )
517+ # # standard error
518+ SE <- lambda * sqrt(vv )
519+ }
520+
521+ # # Save desired quantities depending on SE
511522 if (se )
512523 zse <- SE
524+
513525 if (interval == " confidence" ) {
514526 z <- lambda + outer(SE , ci.q , " *" )
515527 colnames(z ) <- ci.names
516- }
528+ }
529+
517530 }
518531
519532 # # ############################################################
0 commit comments