January 20, 2017

Week 3 Presentation

We're going to embed a plotly plot or two in our presentation.

We'll use some familiar data.

Swiss Data

data(swiss)
fit <- lm(Fertility ~ Catholic, data=swiss)
plot_ly(data=swiss, 
        x=~Catholic, 
        y=~Fertility, 
        size=~Education,
        type="scatter", 
        mode="markers",
        text=rownames(swiss)) %>%
add_trace(data=swiss, 
        x=~Catholic, 
        y=fitted(fit), 
        mode="lines", 
        line=list(width=2))

Swiss Data

Residual Plot

loessA <- loess.smooth(fitted(fit), resid(fit))
plot_ly(x=fitted(fit), 
        y=resid(fit), 
        type="scatter", 
        mode="markers", 
        hoverinfo="x+y", 
        name="Data", 
        marker=list(size=10, opacity=0.5), 
        showlegend=FALSE) %>% 
add_trace(x = loessA$x, 
          y = loessA$y, 
          type = "scatter", 
          mode = "lines+markers", 
          name = "Smooth", 
          line = list(width = 2)) %>%
layout(title = "Residuals vs Fitted Values", 
       plot_bgcolor = "#b6e4e6", 
       width = 1000)        

Residual Plot

The End

Looks like we have some residual fit we need to account for. This is the end of the presentation.