gam

Is it possible to plot the smooth components of a gam fit with ggplot2?

◇◆丶佛笑我妖孽 提交于 2019-11-29 20:12:11
I am fitting a model using gam from the mgcv package and store the result in model and so far I have been looking at the smooth components using plot(model) . I have recently started using ggplot2 and like its output. So I am wondering, is it possible to plot these graphs using ggplot2? Here is an example: x1 = rnorm(1000) x2 = rnorm(1000) n = rpois(1000, exp(x1) + x2^2) model = gam(n ~ s(x1, k=10) + s(x2, k=20), family="poisson") plot(model, rug=FALSE, select=1) plot(model, rug=FALSE, select=2) And I am interest in s(x1, k=10) and s(x2, k=20) not in the fit. Partial answer: I dug deeper into

KDD 2019论文解读:多分类下的模型可解释性

巧了我就是萌 提交于 2019-11-28 19:28:24
前言 模型可解释性是机器学习研究中的一个重要课题。这里我们研究的对象是广义加性模型(Generalized Additive Models,简称GAMs)。GAM在医疗等对解释性要求较高的场景下已经有了广泛的应用 [1]。 GAM作为一个完全白盒化的模型提供了比(广义)线性模型(GLMs)更好的模型表达能力:GAM能对单特征和双特征交叉(pairwise interaction)做非线性的变换。带pairwiseinteraction的GAM往往被称为GA2M。以下是GA2 M模型的数学表达: 其中g是linkfunction,fi和fij被称为shape function,分别为模型所需要学习的特征变换函数。由于fi和fij都是低纬度的函数,模型中每一个函数都可以被可视化出来,从而方便建模人员了解每个特征是如何影响最终预测的。例如在[1]中,年龄对肺炎致死率的影响就可以用一张图来表示。 由于GAM对特征做了非线性变换,这使得GAM往往能提供比线性模型更强大的建模能力。在一些研究中GAM的效果往往能逼近Boosted Trees或者Random Forests [1, 2, 3]。 可视化图像与模型的预测机制之间的矛盾 本文首先讨论了在多分类问题的下,传统可解释性算法(例如逻辑回归,SVM)的可视化图像与模型的预测机制之间存在的矛盾

Is it possible to plot the smooth components of a gam fit with ggplot2?

筅森魡賤 提交于 2019-11-28 16:01:50
问题 I am fitting a model using gam from the mgcv package and store the result in model and so far I have been looking at the smooth components using plot(model) . I have recently started using ggplot2 and like its output. So I am wondering, is it possible to plot these graphs using ggplot2? Here is an example: x1 = rnorm(1000) x2 = rnorm(1000) n = rpois(1000, exp(x1) + x2^2) model = gam(n ~ s(x1, k=10) + s(x2, k=20), family="poisson") plot(model, rug=FALSE, select=1) plot(model, rug=FALSE, select

How to extract fitted splines from a GAM (`mgcv::gam`)

耗尽温柔 提交于 2019-11-28 03:52:12
I am using GAM to model time trends in a logistic regression. Yet I would like to extract the the fitted spline from it to add it to another model, that cannot be fitted in GAM or GAMM. Thus I have 2 questions: How can I fit a smoother over time so that I force one knot to be at a particular location while letting the model to find the other knots? How can I extract the matrix from the fitted GAM so that I can use it in as an impute for a different model? The types of models I am running are to the following form: gam <- gam(mortality.under.2~ maternal_age_c+ I(maternal_age_c^2)+ s(birth_year

Error in model.frame.default: variable lengths differ

给你一囗甜甜゛ 提交于 2019-11-27 14:01:25
On running a gam model using the mgcv package, I encountered a strange error message which I am unable to understand: “Error in model.frame.default(formula = death ~ pm10 + Lag(resid1, 1) + : variable lengths differ (found for 'Lag(resid1, 1)')”. The number of observations used in model1 is exactly the same as the length of the deviance residual, thus I think this error is not related to difference in data size or length. I found a fairly related error message on the web here , but that post did not receive an adequate answer, so it is not helpful to my problem. Reproducible example and data

How to extract fitted splines from a GAM (`mgcv::gam`)

不想你离开。 提交于 2019-11-26 22:20:21
问题 I am using GAM to model time trends in a logistic regression. Yet I would like to extract the the fitted spline from it to add it to another model, that cannot be fitted in GAM or GAMM. Thus I have 2 questions: How can I fit a smoother over time so that I force one knot to be at a particular location while letting the model to find the other knots? How can I extract the matrix from the fitted GAM so that I can use it in as an impute for a different model? The types of models I am running are

Error in model.frame.default: variable lengths differ

半腔热情 提交于 2019-11-26 16:34:40
问题 On running a gam model using the mgcv package, I encountered a strange error message which I am unable to understand: “Error in model.frame.default(formula = death ~ pm10 + Lag(resid1, 1) + : variable lengths differ (found for 'Lag(resid1, 1)')”. The number of observations used in model1 is exactly the same as the length of the deviance residual, thus I think this error is not related to difference in data size or length. I found a fairly related error message on the web here, but that post