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

T distribution #1

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

T distribution #1

wants to merge 16 commits into from

Conversation

Karel-Kroeze
Copy link
Member

No description provided.

anhtth16 and others added 2 commits May 16, 2022 10:08
# min = 1, max = 200, value = 1, step = 1
# )
),
div(# critical values readout
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added critical values readout back in - how this should look/feel/act is still up for debate

output$critical_values <- renderPrint({
tagList(
tags$label("Critical values"),
withMathJax(),
labels() %>% pull(t, df) %>% label_p_value_html() %>% map(p)
labels() %>% select(t, df) %>% purrr::pmap(label_p_value_html) %>% map(p)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pt takes two inputs, need a different approach (purrr:pmap maps over df rows)

outputOptions(output, "mode", suspendWhenHidden = FALSE)
outputOptions(output, "help", suspendWhenHidden = FALSE)
}

shiny::shinyApp(ui, server)
shiny::shinyApp(ui, server) %>% shiny::runApp()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added for non-interactive use (as the file name is non-standard, and doesn't trigger Rstudio black magic integrations

@@ -0,0 +1,163 @@
library(shiny)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I actually forgot to push the progress I already made on the t-distribution app. Sorry!

Copy link
Member Author

@Karel-Kroeze Karel-Kroeze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall!

I left some minor comments.

Suggested changes/improvements;

  • dynamically extend plot range for low df
  • fix y axis to show changes across df
  • add toggleable normal distribution overlay

R/t-distribution Outdated
@@ -0,0 +1,270 @@
# App: t_distribution
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename should be app.R for shiny and Rstudio integrations to work. .R extension is also nice...

R/t-distribution Outdated
STARTING_DF <- 2
STARTING_P_VALUE <-
pt(STARTING_T_VALUE / 2, STARTING_DF, lower.tail = STARTING_T_VALUE <= 0) %>% round(3)
RANGE <- c(-4, 4) # range for T value
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add dynamic range, as with low df the critical values fall outside of the -4, 4 range.

min/max(range, actual) in the render should do the trick

R/t-distribution Outdated
class = "d-flex",
sliderInput("alpha", "Type I error, \\(\\alpha\\)", 0.01, 0.2, 0.05, 0.01)
),
div(# degree of freedom
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df is required in all modes, it also affects p-values, move outside of conditional panel

R/t-distribution Outdated
crit_lower <- reactive(qt(input$alpha / 2, input$df)) # find lower critical value
crit_upper <- reactive(qt(1 - input$alpha / 2, input$df)) # find upper critical value
data <- reactive(tibble(
t = c(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re; adaptive range, check if critical t falues fall outside of range, and if necessary, extend the range

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need to see if that has implications for the precision, as for df=1 the range is ~-25,25 or so

R/t-distribution Outdated
updateNumericInput(session, "t_value", value = tValue())
}) %>% bindEvent(input$p_to_t)

output$critical_values <- renderPrint({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this was unused, but also defective (can't pull 2 variables into a function like that, the function sees it as one variable.)

See update in my patch, and purrr:pmap

R/t-distribution Outdated

## PLOT ---------------------------------------------------------
output$distribution <- renderPlot({
plot <- data() %>% ggplot(aes(t, d))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that the y scale depends on the degrees of freedom. We may want to fix the scale to 0,0.4 (ish, whatever is reasonable for df=\Inf), so that changes in y scale are more obvious to see.

Karel-Kroeze and others added 14 commits May 17, 2022 15:07
- Fixed y-axis to show changes across df
- Modified dynamically extend plot range for low df
- Add check box to show normal distribution
- Fixed error not showing df in p_values mode
- Fixed typo error: label_t_value => label_p_value
- Modified dynamically extend plot range for low df
- Add check box to show normal distribution
- Fixed error not showing df in p_values mode
- Fixed typo error: label_t_value => label_p_value
Update display mode
…in previous versions, display breaks for t-values
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.

2 participants