Comments (2)
from gratia.
I wouldn't use get_by_smooth()
for this — it is exported only as a helper for developers wanting to identify and extract a by variable smoother, but what it extracts is a smooth object as presented inside the fitted GAM object.
Use evaluate_smooth()
or draw()
on the fitted model and select the smooth you want. However, in trying draw()
I am seeing a bug which I'll have to fix.
For example:
library('gratia')
library('mgcv')
set.seed(42)
dat <- gamSim(4, n = 400, verbose = FALSE)
m <- gam(y ~ fac + s(x2, by = fac) + s(x0), data = dat)
draw(m, select = 's(x2)')
The latter is supposed to work, but it isn't and I'll raise an issue to get this fixed.
Following on from the above example you could use evaluate_smooth()
to get back the data the draw()
is extracting internally and then draw the plots yourself:
es <- evaluate_smooth(m, smooth = 's(x2)')
es
library('dplyr')
## add 95% credible interval
es <- mutate(es, lower = est - (2 * se), upper = est + (2 * se))
## plot
library('ggplot2')
ggplot(es, aes(x = x2, y = est)) +
geom_ribbon(aes(ymax = upper, ymin = lower, x = x2), inherit.aes = FALSE,
alpha = 0.2) +
geom_line() +
facet_wrap(~ smooth)
Which produces
And then you can modify from there. Or do as draw()
does and prepare separate plots for each smooth, but filtering the es
object on the smooth
column to select each of the smooths in turn and prepare a plot as above for each smooth separately and then use cowplot::plot_grid()
to arrange them on the plot device.
from gratia.
Related Issues (20)
- prediction-based plots when using by matrices in linear functionals HOT 3
- difference_smooths for models with multiple by= variables HOT 5
- Derivatives of the difference between two smooths
- Support for models with `gfam()` family
- `data_sim()`
- gfam support in `appraise()`
- `draw()` works with gfam models HOT 1
- gfam support in `fitted_samples()`
- gfam support in `posterior_samples()`
- gfam support in `smooth_samples()`
- gfam support in `simulate.gam()`
- `compute_partial_residuals` is wrong if deviance residuals are not equivalent to pearson residuals? HOT 2
- Ensure continuity of gam from start of series to end of series HOT 1
- Tests fail with current version of `Matrix` (1.6-5): `function 'chm_factor_ldetL2' not provided by package 'Matrix'` HOT 3
- Improve plotting code for SOS (spline-on-the-sphere) smooths
- Work towards bayesplot and loo integration?
- Select mvn_method when running `fitted_samples()` HOT 1
- shift=TRUE not working for confint.gam() HOT 5
- Possible PR: making posterior draws compatible with MCMC diagnostic packages
- `draw()` fails with `parametric = TRUE` if there aren't any parametric effects to actually plot
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gratia.