The aim of this experiment is to explore the effects of age, period and cohort. Thus, none of them can be thrown.

> 
> Therefore, the assumption of no cohort effects greatly simplifies estimations but can lead to model misspecification and is inconsistent with accumulating evidence of cohort changes in a variety of health outcomes and mortality'.,
> *'Age-Period-Cohort Analysis'. Yang Yang(2013) P.64*
> 
> 
> 

There are numerous approaches to solving the unidentified problem, the one I choose here is constrained generalized linear model, CGLIM.
I also tried to add nonlinear term into the model, i.e. $age^2$, but NAs still appear.

I tried to use `restriktor` package to fit the count data with constrained poisson regression.

The sample data is generated by the code below:

```
library(tidyverse)
library(restriktor)

set.seed(123)
period_test = rep(seq(2000,2020,5),3)
age_test = c(seq(30,50,5),seq(50,70,5),seq(70,90,5))
cohort_test = period_test-age_test
period_test = period_test %>% fastDummies::dummy_cols() %>% modify(as.factor)
names(period_test) = names(period_test) %>% gsub('.data_','period_',.)
death_data = c(rpois(5,30),rpois(5,20),rpois(5,20))

testing = data.frame(period_test,age_test,cohort_test,death_data)

```

Then I fit the data with glm. The age, period and cohort term are unidentified because of linear dependent. Therefore, I would like to use `restriktor` package to fit the poisson regression with  

equality constraint.

```
tt = glm(death_data~period_2000+period_2005+period_2010+period_2015+period_2020+as.factor(age_test)+as.factor(cohort_test),family = poisson,data = testing)

my_constraints = 'period_20001 = period_20051'
restriktor(tt,my_constraints)

```

The glm result for `tt` is:

```
Call:  glm(formula = death_data ~ period_2000 + period_2005 + period_2010 + 
    period_2015 + period_2020 + as.factor(age_test) + as.factor(cohort_test), 
    family = poisson, data = testing)

Coefficients:
               (Intercept)                period_20001                period_20051                period_20101                period_20151  
                    3.8729                     -0.3466                     -1.2339                     -0.6949                     -0.9826  
              period_20201       as.factor(age_test)35       as.factor(age_test)40       as.factor(age_test)45       as.factor(age_test)50  
                        NA                      0.6931                      0.3483                      0.6650                     -0.2094  
     as.factor(age_test)55       as.factor(age_test)60       as.factor(age_test)65       as.factor(age_test)70       as.factor(age_test)75  
                    0.7320                     -0.1865                      0.7943                     -0.2683                          NA  
     as.factor(age_test)80       as.factor(age_test)85       as.factor(age_test)90  as.factor(cohort_test)1950  as.factor(cohort_test)1970  
                        NA                          NA                     -1.5703                     -0.4266                          NA  

Degrees of Freedom: 14 Total (i.e. Null);  0 Residual
Null Deviance:      46.46 
Residual Deviance: -1.91e-14    AIC: 104.4

```

There are NAs in the coefficients.
Then, I use the following constraint:`my_constraints = 'period_20001 = period_20051'`

The result of restriktor function is :

```
> restriktor(tt,my_constraints)
Error in qr.default(t(ceq.JAC)) : 
  NA/NaN/Inf in foreign function call (arg 1)

```

What can I do to fit with equality constrained glm...? Please give me some advice, thank you!

---

Thank for Dave's reminder, my purpose for fitting constrained poisson regression is to plot a ***Forest plot***:
something like this:

[![enter image description here](https://i.stack.imgur.com/yZ2yA.png)](https://i.stack.imgur.com/yZ2yA.png)

from
[wiki](https://en.wikipedia.org/wiki/Forest_plot#/media/File:Generic_forest_plot.png)

Therefore, I am wondering whether the confidence intervals of period\_2000, period\_2005 will be the same or not if I use Dave's method.