- Waiting vs. Eruptions
- Faithful dataset
- Importance of sample size and line of best fit
- ggplotx2
- plotlyx1
2024-04-05
model: \(\text{Waiting } = y = \beta_0 + \beta_1\cdot \text{eruptions} + \varepsilon\), where \(\varepsilon \sim \mathcal{N}(\mu=0, \sigma^2)\)
Fitted: \(\text{Waiting } = y = \hat{\beta}_0\) - \(\text{estimate of } \beta_0\) + \(\hat{\beta}_1 - \text{estimate of } \beta_1 \cdot \text{eruptions}\)
## eruptions waiting ## 1 3.600 79 ## 2 1.800 54 ## 3 3.333 74 ## 4 2.283 62 ## 5 4.533 85 ## 6 2.883 55
As you can imagine, the slope and position of the line of best fit would be different between the two groups. Choosing the best sample for the model would make our linear function of “Waiting time” stronger. It is also important the assume that the randomness or noise of our data is normally distributed.
suppressMessages(library(plotly)) library(magrittr) data(faithful) mod = lm(waiting ~ eruptions, data=faithful) x = faithful$eruptions;y = faithful$waiting xax <- list( title = "Eruptions", titlefont = list(family="Modern Computer Roman") ) yax <- list( title = "Waiting", titlefont = list(family="Modern Computer Roman") ) fig <- plot_ly(x=x, y=y, type="scatter", mode="markers") %>% add_lines(x = x, y = fitted(mod)) %>% plotly::layout(xaxis = xax, yaxis = yax)