Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethinking_2 Chp_4: Patsy usage for B-Spline #124

Open
jdmoore7 opened this issue Nov 11, 2020 · 0 comments
Open

Rethinking_2 Chp_4: Patsy usage for B-Spline #124

jdmoore7 opened this issue Nov 11, 2020 · 0 comments

Comments

@jdmoore7
Copy link

In section 4.74, the following code block is used:

from patsy import dmatrix
B = dmatrix(
    "bs(year, knots=knots, degree=3, include_intercept=True) -1",
    {"year": d2.year.values, "knots": knot_list[1:-1]},
)
  • I'm confused why knot_list[1:-1] is used; not explained in official textbook (to my knowledge) or in code block.
  • Not clear on why -1 was used in the formula-like string provided.

From Patsy official documentation:
https://patsy.readthedocs.io/en/latest/API-reference.html#patsy.bs

The - 1 is because one degree of freedom will be taken by the intercept; alternatively, you could leave the intercept term out of your model and use bs(x, num_bins, degree=0, include_intercept=True)

However, I've tried both variants, noting that they produce different results.
Could you describe what effect the declaration of B is supposed to have?

@jdmoore7 jdmoore7 changed the title Ch4 Patsy usage Rethinking_2 Chp_4: Patsy usage for B-Spline Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant