Skip to content

Commit

Permalink
added continuous example
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeatman committed Mar 30, 2024
1 parent 81200ff commit 8f4be3b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
27 changes: 26 additions & 1 deletion examples/howto_examples/gam-tract-profiles-example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ggplot(aes(x=nodeID,y=est, color=class)) +

```{r, message=FALSE, warning=FALSE}
# Yet another way to do the same thing and I don't get the difference
g3 <- gam(md ~ s(nodeID,by=class, bs='fs') + s(subjectID, bs= 're'), data=df)
g3 <- gam(md ~ s(nodeID,by=class, bs='fs', k=10) + s(subjectID, bs= 're'), data=df)
# Get smooth estimates
dfs <- smooth_estimates(g3) %>% add_confint(coverage=.68)
Expand All @@ -74,3 +74,28 @@ ggplot(ds,aes(x=nodeID,y=diff)) +
geom_ribbon(aes(ymin = lower, ymax=upper),alpha = 0.2 ) +
geom_hline(yintercept=0)
```

Now look at continuous measures along the tract profile

```{r}
# Yet another way to do the same thing and I don't get the difference
g4 <- gam(md ~ s(nodeID,ALSFRSbulbar, bs='fs', k=10) + s(subjectID, bs= 're'), data=df)
dfs <- smooth_estimates(g4) %>% add_confint(coverage=.68)
#filter(dfs,smooth=='s(nodeID)') %>%
# ggplot(aes(x=nodeID,y=est)) +
# geom_line() +
# geom_ribbon(aes(ymin = lower_ci, ymax=upper_ci),alpha = 0.2 )
# 2d plot showing how tract profiles vary as a function of AFS bulbar
filter(dfs,smooth=='s(nodeID,ALSFRSbulbar)') %>%
ggplot(aes(x=nodeID, y=ALSFRSbulbar))+
geom_raster(aes(fill=est))
# Now plot separate tract profiles by bulbar
dfs %>% mutate(ALSFRSbulbar.factor=factor(ALSFRSbulbar)) %>% filter(ALSFRSbulbar== sort(unique(dfs$ALSFRSbulbar))[2] | ALSFRSbulbar== sort(unique(dfs$ALSFRSbulbar))[99]) %>%
filter(smooth=='s(nodeID,ALSFRSbulbar)') %>%
ggplot(aes(x=nodeID,y=est,color=ALSFRSbulbar.factor)) +
geom_line(show.legend = FALSE) +
geom_ribbon(aes(ymin = lower_ci, ymax=upper_ci),alpha = 0.2 )
```
23 changes: 22 additions & 1 deletion examples/howto_examples/gam-tract-profiles-example.html

Large diffs are not rendered by default.

0 comments on commit 8f4be3b

Please sign in to comment.