Hi,
I need to plot the predicted incidence after running a Poisson regression model when using cubic splines. I am using Stata 13. So basically I want my graph to show the predicted incidence (y axis) over calendar year (x axis).
I have aggregated data of individuals distributed over 19 years, with the dataset containing person years of follow up, calendar year and number of events.
example dataset:
year person_timeyears failures
2009 45.0 1
2010 225.5 6
2011 361.8 7
2012 829.8 21
2013 1059.5 11
..
..
..
My model looks as follows:
______
** First making splines of calendar year with 3 knots:
mkspline calendarsp =year, cubic knots(2009,2012,2017) displayknots
mat knots = r(knots)
** running the Poisson model
poisson failures calendarsp*, e(person_timeyears)
______
I know that when using predict I need to calculate the confidence intervals in a different way than when using a linear regression. At least that what I have been reading in Stata forums. One of the links I used for an example code is: https://www.stata.com/support/faqs/s...ence-intervals.
I tried to use the following code to make the graph, but as you can see in the figure I've attached something goes wrong with the 95%CI. I think this is because I am using splines. I was also wondering whether the red line is at least the predicted incidence. Not sure if I am obtaining the results I want.
______
** code to make a graph:
predict yhat
predict xb,xb
predict error, stdp
generate lb = xb - invnormal(0.975)*error
generate ub = xb + invnormal(0.975)*error
generate plb = invlogit(lb)
generate pub = invlogit(ub)
twoway rarea plb pub year, sort || ///
line yhat year, sort
_____
I hope someone can help me. Thank you!!
Kind regards , Daniela.
I need to plot the predicted incidence after running a Poisson regression model when using cubic splines. I am using Stata 13. So basically I want my graph to show the predicted incidence (y axis) over calendar year (x axis).
I have aggregated data of individuals distributed over 19 years, with the dataset containing person years of follow up, calendar year and number of events.
example dataset:
year person_timeyears failures
2009 45.0 1
2010 225.5 6
2011 361.8 7
2012 829.8 21
2013 1059.5 11
..
..
..
My model looks as follows:
______
** First making splines of calendar year with 3 knots:
mkspline calendarsp =year, cubic knots(2009,2012,2017) displayknots
mat knots = r(knots)
** running the Poisson model
poisson failures calendarsp*, e(person_timeyears)
______
I know that when using predict I need to calculate the confidence intervals in a different way than when using a linear regression. At least that what I have been reading in Stata forums. One of the links I used for an example code is: https://www.stata.com/support/faqs/s...ence-intervals.
I tried to use the following code to make the graph, but as you can see in the figure I've attached something goes wrong with the 95%CI. I think this is because I am using splines. I was also wondering whether the red line is at least the predicted incidence. Not sure if I am obtaining the results I want.
______
** code to make a graph:
predict yhat
predict xb,xb
predict error, stdp
generate lb = xb - invnormal(0.975)*error
generate ub = xb + invnormal(0.975)*error
generate plb = invlogit(lb)
generate pub = invlogit(ub)
twoway rarea plb pub year, sort || ///
line yhat year, sort
_____
I hope someone can help me. Thank you!!
Kind regards , Daniela.
Comment