patsy mgcv splines get penalty matrix

43 views
Skip to first unread message

Luca Puggini

unread,
Aug 4, 2015, 1:32:24 PM8/4/15
to PyData
Hi,
I am currently writing a GAM toolbox for the python statsmodels library  https://github.com/statsmodels/statsmodels/pull/2435#issuecomment-127647937

The project is heavily based on splines that are mostly taken from patsy.

Some splines that I need are available at https://github.com/pydata/patsy/blob/master/patsy/mgcv_cubic_splines.py.
This code is mainly based on the book 'Generalized additive models: an introduction with R'  S. Wood 2006. 

I am wondering if from  mgcv_cubic_splines.py can be extracted the design matrix of the splines and their penalty matrix (defined as S in pag 146 of the Wood's book).  

Let me know.
Thanks,
Luca

Nathaniel Smith

unread,
Aug 4, 2015, 4:29:42 PM8/4/15
to pyd...@googlegroups.com

I'm not sure what you mean about the spline design matrix (I don't have Wood's book in front of me), but I imagine that you could get anything design matrix related from that code directly or with small modifications. AFAIK there isn't any code in there to compute the penalty matrix at all, though.

Your best bet is probably to make your own implementation of the splines, while stealing anything useful from that file in the process?

You might want to ping github user @broessli, who wrote that file. Their motivation was just to be able to take models that were fit using mgcv in R and then do predictions in python, so they didn't need penalty matrices. But they might be interested in helping or have some advice for your project as well.

Good luck!

-n

Reply all
Reply to author
Forward
0 new messages