1 of 16

Live Lecture 1.2

Cause and Effect, Names, Call Expressions,

Data Types, and Tables

Summer 2020

DATA 8

Spring 2020

2 of 16

Announcements

  • Get DSP letters in by the end of the week!
  • Midterm Conflict form due by Fri. 6/26 at midnight
  • HW 1 due Thurs 6/25
  • Update to lab checkoff policy

3 of 16

Agenda

  1. Cause and Effect
  2. Data Types
  3. Names and Functions
  4. Arrays and Tables

4 of 16

Cause and Effect

Two types of studies:

  1. Observational - observe naturally occurring relationships in treatment status and outcome in participants
  2. Experiments - participants are randomly assigned to a treatment group

Confounding factors - systematic differences, other than the treatment itself, between the treatment and control group

5 of 16

Cause and Effect

Confounding factors are more common in observational studies.

Why?

  • In observational studies, we’re observing the world in its “natural” state - including all its systemic biases
  • In experiments, treatments are randomized so confounding factors are more evenly split between the control and treatment group

6 of 16

Agenda

  • Cause and Effect
  • Data Types
  • Names and Functions
  • Arrays and Tables

7 of 16

Data Types

Python has two real number types

  • Int: an integer of any size (e.g. 1, 10, -5, 0)
    • Convert to integer: int('12')
  • Float: a number with an optional fractional part
    • Convert to float: float('1.2')

8 of 16

Data Types

Python has two real number types

  • Int: an integer of any size (e.g. 1, 10, -5, 0)
    • Convert to integer: int('12')
  • Float: a number with an optional fractional part
    • Convert to float: float('1.2')

A string is a snippet of text of any length

  • 'a'
  • “there can be 2 sentences. Here's the second!
    • Convert to string: str(5)
  • 'Word'
  • '3.14'

9 of 16

Agenda

  • Cause and Effect
  • Data Types
  • Names and Functions
  • Arrays and Tables

10 of 16

Names and Call Expressions

f ( 27 )

What function to call

Argument to the function

"Call f on 27."

hours_per_wk = 24*7

Name

Any expression

Names:

Call Expressions:

11 of 16

Names and Call Expressions

f ( 27 )

What function to call

Argument to the function

"Call f on 27."

Call Expressions:

Toy Example:

If we define f(x) = x + 1, then the snippet above would produce a value of 28

12 of 16

Agenda

  • Cause and Effect
  • Data Types
  • Names and Functions
  • Arrays and Tables

13 of 16

Arrays

An array contains a sequence of values

  • All elements of an array should have the same type
  • Arithmetic is applied to each element individually
  • A column of a table is an array

DEMO

A range is an array of consecutive numbers

  • np.arange(end)
  • np.arange(start, end)
  • np.arange(start, end, step)

14 of 16

Table Structure

  • A Table is a sequence of labeled columns
  • Each row represents one individual
  • Data within a column represents one attribute of the individuals

Name

Code

Area (m2)

California

CA

163696

Nevada

NV

110567

Label

Column

Row

15 of 16

Some Table Operations

  • t.select(label) - constructs a new table with just the specified columns
  • t.drop(label) - constructs a new table in which the specified columns are omitted
  • t.sort(label) - constructs a new table with rows sorted by the specified column
  • t.where(label, condition) - constructs a new table with just the rows that match the condition

DEMO

16 of 16

Recap and Questions