Coder Social home page Coder Social logo

noamross / gams-in-r-course Goto Github PK

View Code? Open in Web Editor NEW
239.0 8.0 67.0 15.37 MB

Generalized Additive Models in R: A Free Interactive Course

Home Page: https://noamross.github.io/gams-in-r-course

License: Other

R 22.36% JavaScript 30.34% CSS 47.11% Dockerfile 0.18%

gams-in-r-course's Introduction

Welcome! This is the source repository for Generalized Additive Models in R: A Free Interactive Course, hosted at: https://noamross.github.io/gams-in-r-course.

This course is based on material developed collaboratively over years of teaching workshops with David Miller, Gavin L. Simpson, Eric J. Pedersen.

The site itself is built on an amazing framework created by Ines Montani, originally created for her spaCy course. The front-end is powered by Gatsby and Reveal.js and the back-end code execution uses Binder. Florencia D'Andrea helped port the course materials and made the lovely logo.

If you are interested in building a course on this framework, see Ines's starter repos for making courses in Python and R, and her behind-the-scenes explanation of how the framework works at the original course repo.

The course material in this course is licensed CC-BY, meaning you are free to use it, change it, and remix it as long as you attribute me as the original course. The code is MIT-licensed.

gams-in-r-course's People

Contributors

benmarwick avatar flor14 avatar jmarshallnz avatar maelle avatar noamross avatar xdesro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gams-in-r-course's Issues

Chater 4, section 7

What is the expected purchase probability of a person with 20 accounts (n_acts = 20) if all other values are average? Answer : 0.55
That's correct! Correct! When n_acts is 20 the predicted probability of purchase is about 0.55, all else being equal.

But, When I predict the expected purchase probability of a person with 20 accounts (n_acts = 20) if all other values are average, the answer is 0.4419 with the following code

newdata=data.frame(n_acts=20,
              bal_crdt_ratio=mean(csale$bal_crdt_ratio),
              avg_prem_balance=mean(csale$avg_prem_balance),
              retail_crdt_ratio=mean(csale$retail_crdt_ratio),
              avg_fin_balance=mean(csale$avg_fin_balance),
              mortgage_age=mean(csale$mortgage_age),
              cred_limit=mean(csale$cred_limit)
              )

result=predict(log_mod2,newdata=newdata)
plogis(result)

0.4419715

plogis(result+coef(log_mod2)[1])

0.1331066

mpg dataset?

hi there,
perhaps i've missed something, but where does the mpg dataset come from? there's one in ggplot2, but it's different than the one here. i don't see one available in mgcv or base r...

navigation with arrow keys and Page up and down

Hello Noam,

Very nice you made a course on GAM and mgcv. It seems to me it is only possible to navigate with the mouse using the scrollbar. Would it be possible to add navigation with arrow keys and Page up and down? That would be very convenient!

Alternatively it would be very convenient to have the course in PDF format.

Thank you very much.

Marcel

Chapter 2 section 8 and 9

Hello Noam,
Thank you very much for the GAM and mgcv course.
I am in chapter 2 and When I run codes for sections 8 and 9 in my R studio I only get response vs fitted plot. But when it is run in your platform I see 4 graphs. Am I missing something?

Kind regards

Buddhi
[email protected]

spatial x,y components cover 99.6% deviance

dear Noam,
im dealing with data of nest sites (nido=0/1) and wanted to explore the spatial component. When running the spatial GAM i got the result that Rsq is 1.
Im not sure if im running something. At the momment my response variable (nido=0/1) is set as factor to able to use the binomail-logit function.
any toughts?
thanks so much, your post/site is amazing!!

mod4

Family: binomial
Link function: logit

Formula:
nido ~ te(x, y)

Estimated degrees of freedom:
7.63 total = 8.63

UBRE score: -0.3558566

summary(mod4)

Family: binomial
Link function: logit

Formula:
nido ~ te(x, y)

Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 26.03 97.69 0.266 0.79

Approximate significance of smooth terms:
edf Ref.df Chi.sq p-value
te(x,y) 7.626 7.94 0.267 1

R-sq.(adj) = 1 Deviance explained = 99.6%
UBRE = -0.35586 Scale est. = 1 n = 27

Chapter 4 section 6

The descriptions for the "s(cred_limit)" and "s(mortage_age)" fields in the multiple choice question are swapped.

image

Bootstrapping

Hi! I am a newbie in GAM. It would be great to add in these tutorials how to do bootstrapping. Also include on how to generate plots with bootstrapped CI. Thank you

2.12 Question stems in quiz

Multiple Choice: Which two variables have the greatest worst-case concurvity?

height and ≤n>h

height and weight

≤n>h and wh

weight and wh

Submission give "weight and wh" as correct answer.

navigation with arrow keys and Page up and down

Hello Noam,

Very nice you made a course on GAM and mgcv. It seems to me it is only possible to navigate with the mouse using the scrollbar. Would it be possible to add navigation with arrow keys and Page up and down? That would be very convenient!

Alternatively it would be very convenient to have the course in PDF format.

Thank you very much.

Marcel

PS: I already opened and closed this issue. It seems the issue occurs on some pages of the course and at other pages there is no issue.

Section 4.1

I'm having trouble locating the csale.rds file. I used the code as described on the web page and it resulted in this error: Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :

Any help would be appreciated. Thanks!

Chapter 3, section 8

When try to plot factor-smooths, vis.gam() function results in an error.

model4c <- gam(hw.mpg ~ s(weight, fuel, bs = "fs"),data = mpg, method = "REML")
vis.gam(model4c, theta=125)

Error in persp.default(m1, m2, z, col = col, zlim = c(min.z, max.z), xlab = view[1], :
increasing 'x' and 'y' values expected

Chapter 3.11

In chapter 3, section 11 you give the following example of using tensor interaction terms:

gam(y ~ s(x1) + s(x2) + ti(x1, x2), data = data, method = "REML")

However, that (appears to??) conflict with the recommendation from Simon Wood in A Toolbox of Smooths(see page 28, "Miscellanea"):

However, nested models make most sense if the bases arestrictly nested. To ensure this, smooth interactions shouldbe constructed using marginal bases identical to thoseused for the main effects. gam(y~te(x)+te(z)+te(x,z))would achieve this, for example

Maybe (surely??) I'm missing something here, but if there's a clear explanation it might be worth adding to the course.

Error running the codes

Hello,

I keep getting this error over and over:

imagen

I have tried with different browsers but I keep getting it.

Many thanks

4.1 Intercept of logistic GAM

Here, the value of the intercept is 0.733. We can use the plogis() logistic function to convert it to a probability.
Converted, the intercept is about 0.67.
This means that the model predicts a 67 percent baseline chance of a positive outcome. This is what we would expect if x1 and x2 were at their average values.

-> But, when I predict the model with average value of predictor variable, it is different from intercept. Followings are reproducible example.

> csale=readRDS("csale.RDS")
> log_mod <- gam(purchase ~ s(n_acts),data=csale,family=binomial,method="REML")
> coef(log_mod)[1]

(Intercept)
-1.593984

> predict(log_mod,newdata=data.frame(n_acts=mean(csale$n_acts)))
1 

-1.194276

Chapter 4.2

Hi Noam,

I've been running through the course (which is beautiful, by the way) with no difficulties until now. When trying to run csale <- readRDS("csale.rds") in Chapter 4.2, I receive the error pasted below. R is up-to-date and the "Information" package is loaded (just in case).

Cheers, Brendan

Error message:
Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "rb") :
cannot open compressed file 'csale.rds', probable reason 'No such file or directory'

Remove "Let's Practice" slides

Most slide decks end with a "Let's Practice" or similar sllide but in the current format this isn't really necessary - it's a holdover from the old platform. It would make sense to delete these from the slides markdown files.

Chapter2, seccion 1

Hi, the formula in this section is not the one that shows in the first output (summary(mod_hwy)), it does not count the cylinders at the end. So the results are not the same

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.