1 of 26

API CAN CODE �Data Science Practices

Lesson 3.6: Linear Models with Story Builder

This work was made possible through generous support from the National Science Foundation (Award # 2141655).

2 of 26

Warmup

  • Examine the graph to the right.�
  • What kind of graph is this?�
  • What variable(s) do you see represented? Is there more �than one? �
  • What do you notice? �What do you wonder?�
  • What story does this graph portray?

2

3 of 26

Lesson 3.5 Recap

  • We learned about using CODAP to create confidence intervals

  • Confidence intervals can help us build a more robust estimate for a population mean, or help us see if there is a difference between two populations
  • We looked at Zillow data from two cities to see if there was a difference in housing price in those two cities

3

4 of 26

4

https://www.youtube.com/watch?v=yNN7eDXzlMo

5 of 26

Earthquake Data

We are going to find some data from the US Geological Survey website.

The website is found here.�

Look for the Past Day -> All Earthquakes

dataset (in CSV format). Download this file.�

Geologists might use data like this, and analyze it like this, to study trends in earthquakes!

What makes this a good source for data on earthquakes according to the 5 Vs?

5

6 of 26

Earthquake Data - Converter

We now need to convert this CSV file to JSON so we can use it with our EduBlocks program.

Navigate to the API Can Code CSV Converter.

  • Drag your Earthquakes CSV file where it says “Drop CSV file here.”
  • Click “Get Headers.”
  • Keep all the headers selected. Double-check the number of rows at the bottom. How many earthquakes are in this dataset?
  • Click “Convert Selected Columns to JSON.”
  • Click “Copy JSON” at the bottom and move over to EduBlocks for the next step!

6

7 of 26

Earthquake API

Open this program in EduBlocks. �

  • Clone, rename, and save the program in your library.
  • Paste your JSON into the appropriate box at the top.
  • Run the program!
  • Copy the output…

7

8 of 26

Offline API Backup!

  • If the USGS website is down, you can use a pre-downloaded version of the same data. �
  • Use the backup EduBlocks file we created for this lesson, found here.

8

9 of 26

Intro to CODAP Story Builder

Story Builder records the step-by-step process of the data analysis about a dataset, building out our story about the data. Each step is called “moment” and can be linked to text and graphs.

9

Moment Title

Notes/Description

Graph

(Click the numbers to switch between

Moments)

There’s a quick guide in your handouts for future use!

10 of 26

Earthquakes: EduBlocks to CODAP

Copy the output from your program, and then open CODAP and select “Create New Document.”

  • Go to “Tables” and select “-- New from Clipboard --” which will paste in the data you just copied from your program.

10

NEW: Today, start the Story Builder. This will allow you to save different stages of analysis on a dataset in a multi-slide “story.”

  • Go to “Plugins,” then “Story Telling” → “Story Builder” to start this plugin.

11 of 26

Earthquakes: EduBlocks to CODAP

  • Now you’ve created the first “Moment.”
  • Name your first Moment in the title box (such as “Intro to the Earthquake Dataset”).
  • Look over the data and create any graphs you want to explore the data.
    • How big is your sample?
    • What do you notice? What do you wonder?
  • Take notes of any initial impressions of the data in the description box.

11

  • Finally, save this Moment by clicking the check button.

Moment 1

Step 1: Create a new Moment (already done)

Step 2: Put a title

Step 3: Create your graph(s)

Step 4: Take notes of

important information

Step 5: Save the Moment

12 of 26

Does depth predict magnitude?

  • Now, click the “+” button to create a new Moment and name it “Magnitude.”
  • Create a graph with magnitude on the y-axis.
    • Remember that magnitude is a number on the Richter scale: so each increase of 1 is really an increase of ten times the magnitude!
    • Most earthquakes are below a 4 on the Richter scale.

12

13 of 26

Does depth predict magnitude?

  • Use the Ruler icon to show the mean and standard deviation of this graph.
  • Record the mean, standard deviation, and variance (the standard deviation squared!) in your notes.
  • Then, save the Moment using the check button in the Story Builder.

13

Moment 2

Your results might be different

from the example here! (Why?)

14 of 26

Does depth predict magnitude?

  • Now, create a new Moment and name it “Magnitude and Depth.”
  • Create a new graph.
    • Put magnitude on the y-axis (again).
    • Put depth on the x-axis.
  • In your note, describe the association:
    • what is the direction?
    • what is the form?
    • what is the strength?
    • do you suspect any outliers?

14

Moment 3

  • Save your Moment.

15 of 26

Does depth predict magnitude?

  • Create a new Moment and name it “Relationship between Depth and Magnitude.”
  • In the same graph you just created, use the Ruler icon to add a Least Squares Line to the graph.
  • Take notes of the parameters:
    • Interpret the slope and intercept of your line of best fit.
    • What magnitude would you predict for a depth of 40 miles?

15

Moment 4

Your results might be different

from the example here!

16 of 26

Does depth predict magnitude?

The r2 value presented along with the line of best fit indicates how much variability in the y variable (magnitude) is explained by the x variable (depth).

  • r2 can be as low as 0 �and as high as 1.
  • Is a lot of variability in magnitude explained by depth in your model, or just a little?

16

Moment 4

17 of 26

What does this mean?

  • You’ve now created a linear model of the relationship between depth and magnitude in earthquakes.
  • How would you interpret what your graph is showing? Consider the features of the graph you’ve discussed, like direction and strength.

17

Moment 4

18 of 26

Does depth predict magnitude?

  • Now, go back to the Ruler icon and select Show fit uncertainty to add confidence bands.
    • Think about the model as a tool to predict magnitude from depth.
    • Remember what you learned about confidence intervals, which give a range estimate for a mean.
    • What do confidence bands tell you?
  • Save this Moment and your interpretations.

18

Moment 4

19 of 26

How “wrong” are our predictions?

  • Create a new Moment and name it “Predictions.”
  • Let’s create a new attribute in our original data table.
    • This column of data will be predictions of magnitude based on depth.
    • To create these predictions, go to the top right of the table and click the + button.
    • Name the new attribute predictions, click on it, and go to “Edit Formula…”

19

Moment 5

20 of 26

How “wrong” are our predictions?

  • Let’s create a new attribute in our original data table.
    • In the Edit Formula window, type in:
    • linRegrPredicted(depth, magnitude)
  • This will fill the column with predicted values for magnitude based on the line of best fit!
    • Compare these values to the actual values of magnitude.

20

Moment 5

Hint: Here you can find many other functions that you may need in the future!

21 of 26

How “wrong” are our predictions?

  • Create another new attribute using the + button on the table.
    • Name this one residuals.
    • In the Edit Formula window, type in:
    • magnitude - predictions
  • What values does this produce?
    • We call these numbers residuals. What does a positive residual mean? What does a negative residual mean?

21

Moment 5

22 of 26

How “wrong” are our predictions?

  • Save this Moment in Story Builder with any notes on the two attributes (predictions and residuals) you just created.
  • Optional: Learn more about these two parameters following the guide on the next two skipped slides (#22-23)!

22

23 of 26

How much variance is left?

  • Finally, create a new graph having residuals on the y-axis.
    • Using the Ruler icon, add the mean and the standard deviation to the graph.
    • Calculate the variance of this new graph (the standard deviation squared).
    • How does this variance compare to the original variance of magnitude?

23

Moment 5

24 of 26

How much variance is left?

  • Divide the residuals variance by the magnitude variance.
    • What number does this give?
    • Do you see any relationship between this number and the r2 value you had on your line of best fit?
  • Take a note on this relationship and save this Moment in Story Builder.

24

Moment 5

25 of 26

Exit Ticket

Submit a link to your CODAP program with your Story Builder moments in it.�

List one interpretation you can take away from one of the graphs you created.

25

Possible interpretations to think about:

  • Did you notice a relationship between any variables? Was it a strong relationship? What direction was the association in? What might this mean?�
  • Were variables highly spread-out or less spread-out? What might this mean?�
  • Did you notice any unusual cases? What might these mean about larger trends or patterns?

Use the menu → Share…

→ “Get link to shared view” to get a link to your CODAP.

26 of 26

Thanks!

apicancode@umd.edu

26

This work was made possible through generous support from the National Science Foundation (Award # 2141655).