introduction to generalized additive models
play

Introduction to Generalized Additive Models Noam Ross Senior - PowerPoint PPT Presentation

DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Introduction to Generalized Additive Models Noam Ross Senior Research Scientist, EcoHealth Alliance DataCamp Nonlinear Modeling in R with GAMs Trade-offs in Model


  1. DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Introduction to Generalized Additive Models Noam Ross Senior Research Scientist, EcoHealth Alliance

  2. DataCamp Nonlinear Modeling in R with GAMs Trade-offs in Model Building

  3. DataCamp Nonlinear Modeling in R with GAMs Non-linear Relationships

  4. DataCamp Nonlinear Modeling in R with GAMs Nonlinear Relationships (2) linear_mod <- lm(y ~ x, data = my_data)

  5. DataCamp Nonlinear Modeling in R with GAMs Nonlinear Relationships (3) library(mgcv) gam_mod <- gam(y ~ s(x), data = my_data)

  6. DataCamp Nonlinear Modeling in R with GAMs Basis Functions

  7. DataCamp Nonlinear Modeling in R with GAMs Basis Functions (2) gam_mod <- gam(y ~ s(x), data = my_data) coef(gam_mod) (Intercept) s(x2).1 s(x2).2 7.814448 5.272290 5.104941 s(x2).3 s(x2).4 s(x2).5 1.271135 1.720561 -1.180613 s(x2).6 -2.676133

  8. DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Let's practice!

  9. DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Basis Functions and Smoothing Noam Ross Senior Research Scientist, EcoHealth Alliance

  10. DataCamp Nonlinear Modeling in R with GAMs Getting the right fit Close to the data (avoiding under- fitting) Not fitting the noise (avoiding over- fitting)

  11. DataCamp Nonlinear Modeling in R with GAMs Balancing Wiggliness Fit = Likelihood − λ × Wiggliness

  12. DataCamp Nonlinear Modeling in R with GAMs Choosing the Right Smoothing Parameter

  13. DataCamp Nonlinear Modeling in R with GAMs Smoothing Syntax Setting a fixed smoothing parameter gam(y ~ s(x), data = dat, sp = 0.1) gam(y ~ s(x, sp = 0.1), data = dat) Smoothing via restricted maximum likelihood gam(y ~ s(x), data = dat, method = "REML")

  14. DataCamp Nonlinear Modeling in R with GAMs Number of basis functions

  15. DataCamp Nonlinear Modeling in R with GAMs Basis Function Syntax Setting number of basis functions gam(y ~ s(x, k = 3), data = dat, method = "REML") gam(y ~ s(x, k = 10), data = dat, method = "REML") Use the defaults gam(y ~ s(x), data = dat, method = "REML")

  16. DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Let's practice!

  17. DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Multiple Regression with GAMs Noam Ross Senior Research Scientist, EcoHealth Alliance

  18. DataCamp Nonlinear Modeling in R with GAMs Our Working Dataset: mpg mpg symbol loss make fuel aspir doors style drive eng.loc wb 1 3 NA alfa-romero gas std two convertible rwd front 88.6 2 3 NA alfa-romero gas std two convertible rwd front 88.6 3 1 NA alfa-romero gas std two hatchback rwd front 94.5 4 2 164 audi gas std four sedan fwd front 99.8 5 2 164 audi gas std four sedan 4wd front 99.4 6 2 NA audi gas std two sedan fwd front 99.8 7 1 158 audi gas std four sedan fwd front 105.8 8 1 NA audi gas std four wagon fwd front 105.8 9 1 158 audi gas turbo four sedan fwd front 105.8 10 0 NA audi gas turbo two hatchback 4wd front 99.5 ...

  19. DataCamp Nonlinear Modeling in R with GAMs Multiple Smooths (1) model <- gam(hw.mpg ~ s(weight), data = mpg, method = "REML")

  20. DataCamp Nonlinear Modeling in R with GAMs Multiple Smooths (2) model <- gam(hw.mpg ~ s(weight), data = mpg, method = "REML") model2 <- gam(hw.mpg ~ s(weight) + s(length), data = mpg, method = "REML")

  21. DataCamp Nonlinear Modeling in R with GAMs Multiple Smooths (3) model2 <- gam(hw.mpg ~ s(weight) + s(length), data = mpg, method = "REML")

  22. DataCamp Nonlinear Modeling in R with GAMs Linear terms model2 <- gam(hw.mpg ~ s(weight) + length, data = mpg, method = "REML")

  23. DataCamp Nonlinear Modeling in R with GAMs Linear Terms (2) model2b <- gam(hw.mpg ~ s(weight) + s(length, sp = 1000), data = mpg, method = "REML")

  24. DataCamp Nonlinear Modeling in R with GAMs Categorical Terms (1) model3 <- gam(hw.mpg ~ s(weight) + fuel, data = mpg, method = "REML")

  25. DataCamp Nonlinear Modeling in R with GAMs Categorical Terms (2) model4 <- gam(hw.mpg ~ s(weight, by = fuel), data = mpg, method = "REML")

  26. DataCamp Nonlinear Modeling in R with GAMs Categorical Terms (3) model4b <- gam(hw.mpg ~ s(weight, by = fuel) + fuel, data = mpg, method = "REML")

  27. DataCamp Nonlinear Modeling in R with GAMs NONLINEAR MODELING IN R WITH GAMS Let's practice!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend