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

summary.estimate_slopes() no longer working. #371

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

strengejacke
Copy link
Member

Fixes #345

@strengejacke

This comment was marked as outdated.

@strengejacke
Copy link
Member Author

I see, from the gam-example, and now understand the "segments" idea. Ignore this for now, let's try to make the summary() like it was intended to be, not like I suggested here.

@strengejacke
Copy link
Member Author

More like this?

library(modelbased)
model <- mgcv::gam(Sepal.Width ~ s(Petal.Length), data = iris)
slopes <- estimate_slopes(model, by = "Petal.Length", length = 50)
#> No numeric variable was specified for slope estimation. Selecting `trend
#>   = "Petal.Length"`.
summary(slopes)
#> Average Marginal Effects
#> 
#> Start |  End | Direction | Confidence     
#> ------------------------------------------
#> 1.00  | 1.60 | positive  | Not Significant
#> 1.72  | 1.96 | negative  | Not Significant
#> 2.08  | 3.05 | negative  | Significant    
#> 3.17  | 3.41 | negative  | Not Significant
#> 3.53  | 3.65 | positive  | Not Significant
#> 3.77  | 4.25 | positive  | Significant    
#> 4.37  | 6.18 | positive  | Not Significant
#> 6.30  | 6.90 | negative  | Not Significant
#> 
#> Marginal effects estimated for Petal.Length
#> Type of slope was dY/dX

model <- mgcv::gam(Sepal.Width ~ s(Petal.Length, by = Species), data = iris)
slopes <- estimate_slopes(model,
  trend = "Petal.Length",
  by = c("Petal.Length", "Species"), length = 20
)
summary(slopes)
#> Average Marginal Effects
#> 
#> Group      | Start |  End | Direction | Confidence     
#> -------------------------------------------------------
#> setosa     |  1.00 | 1.62 | positive  | Not Significant
#> versicolor |  3.17 | 5.04 | positive  | Significant    
#> virginica  |  4.73 | 5.66 | positive  | Significant    
#> virginica  |  5.97 | 6.90 | positive  | Not Significant
#> 
#> Marginal effects estimated for Petal.Length
#> Type of slope was dY/dX

Created on 2025-01-29 with reprex v2.1.1

@strengejacke
Copy link
Member Author

m <- lm(Sepal.Width ~ Petal.Length * Petal.Width, data = iris)

modelbased::estimate_slopes(m, "Petal.Length", by = "Petal.Width") |> summary()
#> Average Marginal Effects
#> 
#> Start |  End | Direction | Confidence     
#> ------------------------------------------
#> 0.10  | 0.90 | negative  | Significant    
#> 1.17  | 1.70 | negative  | Not Significant
#> 1.97  | 2.23 | positive  | Not Significant
#> 2.50  | 2.50 | positive  | Significant    
#> 
#> Marginal effects estimated for Petal.Length
#> Type of slope was dY/dX

modelbased::estimate_slopes(m, "Petal.Length", by = "Petal.Width", length = 150) |> summary()
#> Average Marginal Effects
#> 
#> Start |  End | Direction | Confidence     
#> ------------------------------------------
#> 0.10  | 1.15 | negative  | Significant    
#> 1.16  | 1.69 | negative  | Not Significant
#> 1.71  | 2.44 | positive  | Not Significant
#> 2.45  | 2.50 | positive  | Significant    
#> 
#> Marginal effects estimated for Petal.Length
#> Type of slope was dY/dX

Created on 2025-01-29 with reprex v2.1.1

@DominiqueMakowski
Copy link
Member

Ill be travelling over this weekend so I'll get to this next week!

@strengejacke
Copy link
Member Author

Yeah, I don't think this PR is too urgent.

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

Successfully merging this pull request may close these issues.

summary.estimate_slopes() no longer working.
2 participants