2

I'm trying to fit a generalized Lee-Carter model with the R package gnm. I built a data frame

EXPO <- read.table("dati/Exposures.txt",header=TRUE,skip=0)
DEATH <- read.table("dati/Deaths.txt",header=TRUE,skip=2) 
base=data.frame(
D=DEATH$Total,
E=EXPO$Total,
X=as.factor(EXPO$Age),
T=as.factor(EXPO$Year))

Now, while this works

LC1 <- gnm(D/E~ as.factor(X)+Mult(as.factor(X),as.factor(T)),
                 weights=E,family=binomial(link="logit"),data=base)

when I move to this one I get an error

LC2 <- gnm(D/E~ as.factor(X)+instances(Mult(as.factor(X),as.factor(T)),2),
                 weights=E,family=binomial(link="logit"),data=base).

Specifically,

Error in eval(expr, envir, enclos) : object 'D/E' not found

I already tried to replace "D/E" with "base$D/base$E" in the formula, but it didn't work...

  • 1
    If you compute `DE = D/E` beforehand, does that work? `gnm`'s `instances` might not appropriately handle complex responses. – Josh Aug 03 '15 at 16:03

1 Answers1

1

I am the maintainer of gnm. This appears to be a bug in instances which I will make a note to fix. In the meantime you can specify the instances in long form:

LC2 <- gnm(D/E ~ as.factor(X) + Mult(as.factor(X), as.factor(T), inst = 1) + 
           Mult(as.factor(X), as.factor(T), inst = 2),
           weights = E, family = binomial(link = "logit"), data = base)

Alternatively pre-computing the proportions as suggested by Josh will also work.

Heather Turner
  • 3,264
  • 23
  • 30