From 8f4be3b6025c0ab7fe24ce7a0df757f2e744708e Mon Sep 17 00:00:00 2001 From: "Jason D. Yeatman" Date: Sat, 30 Mar 2024 07:35:11 -0700 Subject: [PATCH] added continuous example --- .../gam-tract-profiles-example.Rmd | 27 ++++++++++++++++++- .../gam-tract-profiles-example.html | 23 +++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/examples/howto_examples/gam-tract-profiles-example.Rmd b/examples/howto_examples/gam-tract-profiles-example.Rmd index 25db99aac..5088a8f50 100644 --- a/examples/howto_examples/gam-tract-profiles-example.Rmd +++ b/examples/howto_examples/gam-tract-profiles-example.Rmd @@ -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) @@ -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 ) + +``` diff --git a/examples/howto_examples/gam-tract-profiles-example.html b/examples/howto_examples/gam-tract-profiles-example.html index 395c1cd3e..2579c29f0 100644 --- a/examples/howto_examples/gam-tract-profiles-example.html +++ b/examples/howto_examples/gam-tract-profiles-example.html @@ -392,7 +392,7 @@

GAMs Tutorial

geom_ribbon(aes(ymin = lower_ci, ymax=upper_ci),alpha = 0.2 )

# 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)
 
@@ -410,6 +410,27 @@ 

GAMs Tutorial

geom_ribbon(aes(ymin = lower, ymax=upper),alpha = 0.2 ) + geom_hline(yintercept=0)

+

Now look at continuous measures along the tract profile

+
# 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 )
+