[R] rms package: error with Glm
Mark Seeto
markseeto at gmail.com
Mon Mar 2 21:49:51 CET 2015
Dear R-help,
I'm getting an error with Glm (from the rms package) when the
equivalent model using glm does not give an error. This is using rms
4.3-0 in R 3.1.1.
An example is shown below. I have set the seed value, but the error is
not specific to this seed value.
Thanks for any help anyone can give.
Mark Seeto
#############################################################################
library(rms)
set.seed(1)
n <- 100 # sample size
beta0 <- 3.7
beta1 <- 1.5
beta2 <- 0.9
beta3 <- 0.5
rate.x1 <- 2
mean.x2 <- 1
sd.x2 <- 2
nu <- 1.3
d <- data.frame(x1 = rexp(n, rate = rate.x1),
x2 = rnorm(n, mean.x2, sd.x2))
d$y <- rgamma(n, shape = nu,
rate = nu/exp(beta0 + beta1*d$x1 + beta2*d$x2 + beta3*d$x2^2))
glm(y ~ x1 + x2 + I(x2^2), family = Gamma(link=log), data=d) # No error
Glm(y ~ x1 + pol(x2, 2), family = Gamma(link=log), data=d) # Error shown below
## Error in glm.fit(x = X[, "Intercept", drop = FALSE], y = Y, weights
= weights, :
## NA/NaN/Inf in 'x'
## In addition: Warning message:
## step size truncated due to divergence
More information about the R-help
mailing list