Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

13 Ddply

on

  • 1,811 views

 

Statistics

Views

Total Views
1,811
Views on SlideShare
1,810
Embed Views
1

Actions

Likes
0
Downloads
25
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    13 Ddply 13 Ddply Presentation Transcript

    • Stat405 ddply case study Hadley Wickham Wednesday, 7 October 2009
    • 1. Feedback & homework & project 2. Overall goal: dual-sex names vs. errors 3. Selecting smaller subset 4. Classification 5. Individual exploration Wednesday, 7 October 2009
    • Feedback I’ll try and go slower when writing things on the board. Remind me! Too much homework? Will try to reduce from now on. This week’s homework is a bit different. Wednesday, 7 October 2009
    • Homework If you need more practice, all function drills, along with answers, are available on line. Running behind on grading, sorry :( Common mistakes Wednesday, 7 October 2009
    • even <- function(x) { is_even <- x %% 2 == 0 if (is_even) { print("Even!") } else { print("Odd!") } } # Problems # * does it work with vectors? # * can we easily define odd in terms of even? Wednesday, 7 October 2009
    • even <- function(x) { x %% 2 == 0 } even(1:10) odd <- function(x) { !even(x) } # In general, always should return something useful # from functions, rather than printing or plotting Wednesday, 7 October 2009
    • area <- function(r) { a <- pi * r ^ 2 a } # Not necessary! area <- function(r) { pi * r ^ 2 } Wednesday, 7 October 2009
    • # Choose from a, b and c with equal probability x <- runif(1) if (x < 1/3) { "a" } else (x < 2/3) { "b" } else { "c" } # OR sample(c("a","b","c"), 1) Wednesday, 7 October 2009
    • Project Still working on grading. Will have back to you by next Wednesday (no class on Monday). Next project due Oct 30. Basically same as last time, but working with baby names and you need to include an external data source. Wednesday, 7 October 2009
    • Questions For names that are used for both boys and girls, how has usage changed? Can we use names that clearly have the incorrect sex to estimate error rates over time? Wednesday, 7 October 2009
    • Getting started options(stringsAsFactors = FALSE) library(plyr) library(ggplot2) bnames <- read.csv("baby-names.csv") Wednesday, 7 October 2009
    • First task Identify a smaller subset of names that been in the top 1000 for both boys and girls. ~7000 names in total, we want to focus on ~100. In real-life would probably use more, but starting with a subset for easier exploration is still a good idea. Wednesday, 7 October 2009
    • First task Identify a smaller subset of names that been in the top 1000 for both boys and girls. ~7000 names in total, we want to focus on ~100. In real-life would probably use more, but starting with a subset for easier exploration is still a good idea. Take two minutes to brainstorm what variables we might to create to do this. Wednesday, 7 October 2009
    • Your turn Summarise each name with: the total proportion of boys, the total proportion of girls, the number of years the name was in the top 1000 as a girls name, the number of years the name was in the top 1000 as a boys name Hint: Start with a single name and figure out how to solve the problem. Hint: Use summarise Wednesday, 7 October 2009
    • times <- ddply(bnames, c("name"), summarise, boys = sum(prop[sex == "boy"]), boys_n = sum(sex == "boy"), girls = sum(prop[sex == "girl"]), girls_n = sum(sex == "girl"), .progress = "text" ) nrow(times) times <- subset(times, boys_n > 1 & girls_n > 1) Wednesday, 7 October 2009
    • ●●●●●●●●●● ●●●●● ● ● ● ● ● ● ●● ● ● ● ● ●●●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● 120 ● ● ● ●● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● 100 ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●●● ● ●● ● ● ● 80 ● ●● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● girls_n ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● 60 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● 40 ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● 20 ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ●●● ● ● ● ● ● ● ● ● ● ●● ●● ●● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● 20 40 60 80 100 120 boys_n Wednesday, 7 October 2009
    • New functions: 80 pmin(a, b) pmax(a,b) 60 count 40 20 0 20 40 60 80 100 120 pmin(boys_n, girls_n) Wednesday, 7 October 2009
    • qplot(boys_n, girls_n, data = times) qplot(pmin(boys_n, girls_n), data = times, binwidth = 1) times$both <- with(times, boys_n > 10 & girls_n > 10) # Still a few too many names. Lets focus on names # that have managed a certain level of popularity. qplot(pmin(boys, girls), data = subset(times, both), binwidth = 0.01) qplot(pmax(boys, girls), data = subset(times, both), binwidth = 0.1) qplot(boys + girls, data = subset(times, both), binwidth = 0.1) Wednesday, 7 October 2009
    • # Now save our selections both_sexes <- subset(times, both & boys + girls > 0.4) selected_names <- both_sexes$name selected <- subset(bnames, name %in% selected_names) nrow(selected) / nrow(bnames) Wednesday, 7 October 2009
    • Yearly summaries Next problem is to classify which names are dual-sex, and which are errors. To do that, we’ll need to calculate yearly summaries for each of those names, and use our knowledge of names to come up with a good classification criterion. Wednesday, 7 October 2009
    • Your turn For each name, in each year, figure out the total number of boys and girls. Think of ways to summarise the difference between the number of boys and girls, and start visualising the data. Wednesday, 7 October 2009
    • bysex <- ddply(selected, c("name", "year"), summarise, boys = sum(prop[sex == "boy"]), girls = sum(prop[sex == "girl"]), .progress = "text" ) # It's useful to have a symmetric means of comparing # the relative abundance of boys and girls - the log # ratio is good for this. bysex$lratio <- log10(bysex$boys / bysex$girls) bysex$lratio[!is.finite(bysex$lratio)] <- NA Wednesday, 7 October 2009
    • 2 1 0 lratio −1 −2 1880 1900 1920 1940 1960 1980 2000 year Wednesday, 7 October 2009
    • Ronald ● ●●● ●●● ●● Mark ● ●●●● ●● ●● ●● Larry ● ●● ● ● ● ●●● ● ●● ● Richard ●●●●●●●● ● ●●● ● ●● ●●● ●● ● ●● ● ● ●● ● ● ● ● ●● ●● ●●● ● William ●● ●●● ● ●●●●●● ● ●●●●● ● ●●●● ● ● ●● ●● ●●●● ●●●● ● ●● ●●● ●●● ● ●● ●● ●● ● ●● ● ●● ●● Edward ● ●●●●●●●●●● ● ● ●●●●●● ● ● ●●●●● ● ●● ● ● ●● ●● Thomas ● ●●●●●●●●● ● ● ●●● ●●●●●●● ● ●● ●●● ●● ●●● ● ● ●●● ● Donald ●●● ● ●●● ●● ●●● ● ● ●● ●● ● David ● ●●●●●● ●●●●●● ● ●●●●●● ● ●● ●● ●●●●● ●●● ●● ●●● ● ●●●● ●● ● John ●●●●● ● ●●●●●● ●●● ● ●●●●●● ● ●● ●● ● ●●● ●● ●●● ● ●●●● ● ● ● ●●●● ● ● ●● ● ● ● Robert ●● ●●●●●●●●● ● ●● ●●●●●●●●● ●● ● ●●●● ●● ● ●● ●●● ● ●●● ●●●●●● ●● ● Harry ● ●●●● ●● ●● ● ●● ● ● ● James ●●●●●●●●●●●● ●●●●●●● ●●● ● ●● ●●●●● ●●● ●● ●●●● ●● ● ●● ●● ● ●● ●● ●● Joseph ●●●●●●●●●●● ●●●●●●●●● ●● ●●● ●●●●●●● ● ●●●●●●●● ● ● ●● ● ● ● ●●● ●● ● Frank ● ●●●●●●●●●● ● ●●● ●●● ● ● ●●●● ●● ●● ● ● ● ● Charles ●●●●●●●●●● ●● ● ● ●● ●●●●●●● ● ●●●●●● ●● ● ●●●●●● ●●●● ●● ● ●● ● ● Albert ●● ● ●● ●● ● ● ●● ●● ● Paul ● ●●● ●● ● ● ● ●●●● ●●●● ● ●● ●● ● Michael ●● ●●● ●●●● ● ● ●●●●● ●●●● ●● ●● ● ● ● ●● ● ● ● ●● ● ●● ● Brian ● ●● ●● ● ●●●● Kenneth ●● ● ●● ●● ● ● ● ● ● ●● Harold ●●●●● ●● ● ●●●● ●● Walter ●●● ●●●●●●● ● ● ●●●● ●● ●● ●●● ● ●● ● ● ● Arthur ●●●● ● ● ● ● ● ●●● ● ●● ● ●● ● ● ●● ● Matthew ● ●● ● ●● ● ●●● ● George ●●●●●●●● ●● ● ●●●●●● ●● ● ●●●● ● ●● ●●●●● ● ●● ●●●● ●●● ● Kevin ● ● ●● ● ● ●● ● ● Christopher ●●● ●●● ●●● ● ● ●●● ● ●●● Jack ●● ●● ●● ● ● ●●● ●● ● Henry ●●●●●●●● ●●● ●●● ●●●●● ●● ●●● ●● ● ● ● ●●● ●● ● ●● ●●● ●● Fred ●● ● ●● ● ● ●●● ● ●● ●● ●● Jason ●●● ● ●● ● ●● ●● Joshua ● ●● ● ●● ● ● ● Eric ● ●● ●●● ● ●● ●● reorder(name, lratio, na.rm = T) Daniel ●● ● ●● ● ●● ● ●● Anthony ●●● ● ●● ●●● ● ●● ●● ●● ● ●● Louis ● ● ●●●● ● ●●● ● ● ●●●● ● ● Joe ●●●●●●● ●●● ● ● ●●● ●●●●●●● ● ● ●● ● ●●●● ● ● ●● ● ● ●● ●● ● ● ● ●● Ryan ●● ●●● ●●●● ● ●● ● ●● ●●●● ● ● ●● ● ●●● ●● ● Jerry ●● ● ● ●● ●● ●● ●● ●● ●● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ● ● ● ● ●● ● ●● ●● ●● ● ●● Willie ●●●●●● ●● ●● ●●● ● ●● ●● ●●●●●● ● ● ● ●● ● ●● ● ● ●●●●●● ●●●●●● ● ●● ● ● ● Shirley ●● ● ●●● ●●● ●●● ●● ● ●● ●● ● ●● ● ●● ●● ● ●● ● ● ● ● ● ●● ●●● ●● ●●● ●● ●●● ● ● ●● ●●● ●● ● ● ● ● ● ●● Ashley ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ●●● ● ●● ● ● ●● ● Carol ●●●● ● ● ●● ●● ●● ● ● ● ●● ●● ● ● ● ●●●● ● ●●●● ● ●● ●●● ●● ● ● ● ● ●● ●● ●● ● ●● ●● ● ● ● Frances ● ●● ●● ●●●●●● ● ● ●● ●● ● ●●● ● ● ●● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● Julia ● ●● ● ● ●●● ● ● ● Doris ● ●●●●● ● ● ● ● ●● ●●● ● ● ● ● ● ● ●●● ● ● Irene ● ●●●● ● ● ● ● ● ● Louise ●●●● ● ●●●● ●●●●●● ● ●● ●● ● ●● ● ● ● Rose ● ●● ● ●● ●● ● ● ●● ●● ●●● ● ●● ● ●● ●● Florence ● ●●●● ● ●● ● ●● ●●●● ● ●●● ● ●● ●● ● Ethel ● ●●● ●●●● ● ● ● ●● ●● ●●● ● ●● ●● ● ● ●● ● Edith ● ●●● ● ●● ● ●● ● ●● ● ● ● Kimberly ● ●● ●● ● ●● ●●● ● ● ● ● ● ●● ● Annie ● ●●● ●● ● ●●● ● ● ●● ● ● ●●● ● ●●● ● ● ●● ●● Edna ● ●●●●●●● ●●●● ● ●●●● ● ● ● Minnie ● ●●● ●●●●● ●● ●● ●● ●● ● ● ● ● Grace ● ● ●●● ● ● ● ●● ● ● ●●● ●● ● ● Clara ● ●●●● ●● ● ● ● ●●● ●● ● ●● Bertha ● ● ● ● ● ●●● ● ● ● ● ●● ● ●● ●● Lillian ● ●●●●● ● ● ● ● ●● ● ● ●● ●● ● ● Martha ●●● ●●● ● ●●● ●● ● Marie ●●●●●●●● ●●●● ● ● ● ●● ● Emma ● ● ● ● ● ●●● ● ● ● ●● ●● ● ●● ● Mildred ●● ●● ●●●● ●●● ● ● ● ● ●● ● ● ● Alice ●●●● ●●●● ● ● ●● ●●● ● ●● ●● ●●● ● Anna ●●●●●●●●● ● ● ● ●● ● ● ● ●● ● ● ● ●● ● ● Sarah ● ●● ●● ● ●● ● ● ● ● ● ●● ●● ● Elizabeth ●● ●●●●●●● ● ● ●● ●●●●●● ● ● ●●●●●●● ●●● ●● ●●●●● ●● ● ●● ●● Ruth ●● ●● ● ●●● ●● ● ● ●● ● ●●● ● ● ● ●●● ● ●● ● ●●● ● ● ● Margaret ●●● ● ●●●●●● ●● ●● ● ● ●●●●●●●● ● ● ●●● ●● ● ●●●● ● ●● ● ●●● ●● ● Helen ●●●●● ●●●● ● ● ● ● ●● ●●●●● ● ● ● ● ● ●● ●● ●● ● ● ●● ● ●● ●●● Virginia ●● ●●● ●●●● ●● ●● ● Dorothy ● ● ● ●●● ●●● ● ● ● ● ● ● ●● ●●● ● ● ● ●● ● ●● ● ●● ● ● ●● ● Mary ● ●●●●●●●●●●●● ● ●●●●●●●●●● ●●● ● ● ● ●●●● ●● ●● ● ● ● ●●● ●●● ● ●● ● ● ● ● Betty ● ●●●● ●● ●●● ●● ● ● ●●● ●● ●● ● Michelle ●●● ● ●●● ● ●● ● ● Sharon ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● Jessica ● ●●●● ● ●● ● Melissa ●●● ● ● ●● ●●●● ●● ●● Nancy ●● ●● ● ● ● ●● ● ● ● ● ● ● Jennifer ● ●●● ● ● ● ●●● ●●● ●● ● Amanda ● ●●● ● ●● ● ●● Patricia ●●● ●● ●●● ● ●● ● ●●● ●● ●●●● ● ●● ●● ●● ●● Donna ● ●●● ● ●● ● ● ● ● ● Sandra ●● ●●● ●● ●● ● ● ● ● Barbara ● ●●●● ●●●● ● ● ● ● ●● ● ●● ● Lisa ●●● ●●● ●● ●● ● ●● Karen ●● ● ●● ● ● ●● ● ● ● ● ● Linda ● ● ● ●●● ● ● ●● ● ●● ● ●●●●●●● ● Susan ●● ●●●● ● ● ●● ●● ● ● ●● ● ● ● ● −2 −1 0 1 2 lratio Wednesday, 7 October 2009
    • Ronald ● ●●●● ● ●● ● ● Mark ● ● ● ● ● ●● ●● ●● ● ● Larry ●● ●●● ●● ●●● ● ● ● Richard ● ● ● ● ●●● ●●● ● ●●● ●● ●● ●● ● ● ● ● ●● ●●● ● ●● ●● ● ● ● ● ● ● ● ●● ● ● ● William ● ●●●● ● ●● ●● ●●●● ● ● ● ●●●●● ● ● ●● ● ● ● ●● ●●● ●● ● ● ●● ● ● ● ●● ●● ●●● ●●● ● ● ● ●● ●●●●● ●● ● ●● ● ● ● ● ● Edward ● ● ● ●● ● ●● ● ●●●● ● ● ● ● ● ●● ●● ● ● ● ● ● ● ●● ● ● ● Thomas ●● ● ● ● ● ●●●● ●●● ● ● ●● ● ● ● ● ● ●●●● ●● ● ● ● ● ● ●●●●●●● ●● ●●●● ● ●●● ● Donald ●● ●● ●●● ● ●●● ● ●●● ●● ●● ● ● ● David ● ● ●● ●●● ●●● ● ● ● ●●● ● ● ● ● ● ● ●● ●●● ● ● ● ● ●●● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● John ● ●●●● ● ●●●●● ●●●●●●●●● ● ●●● ● ●●●●● ●●● ● ●●●●● ●●● ● ●● ●● ●● ● ●● ●● ●● ● ● ●● ●● ● ● ● ●● ●●● ● ● Robert ●●●●● ●●●●●●●●●●●● ●● ● ● ●●● ● ● ●●●●●●●● ●●●●● ● ●● ● ● ● ●● ●● ● ●● ● ● ●●● ● ● ●● ● ● ●● ●● ● ● ● Harry ●● ● ● ● ● ● ● ● ● ●● ● ●● James ● ●●●● ●●● ●●●●●●●●●●●●● ● ● ●●●● ● ● ●●● ●●●●●●● ●● ● ●●● ●● ●● ● ●●● ● ● ●● ● ●●● ● ● ●●● ● ●● ●● ●● ●● Joseph ●●●●●●●● ●● ●●●●● ● ● ●●●● ● ● ● ● ● ●● ●●●●● ● ●●● ●● ● ●● ●● ●● ●●● ● ●● ● ● ●●● ●● ● Frank ● ●●● ●●●●● ● ● ●●●●●● ● ● ● ●●●● ● ●● ● ● ●●● ● ● ● ● ● Charles ● ● ●●●●●●●●●●●●● ● ● ● ●● ● ●●●●● ●●●●●●●● ● ● ● ● ● ● ●●●●●● ●● ● ● ●● ●● ● ● ●● ● ●● ●● ● Albert ● ●● ● ● ● ● ●●● ● ● ● ● ● Paul ●● ● ● ●●● ●●● ● ● ● ● ● ● ●●● ● ● ● Michael ●● ●●●●●●● ● ●● ● ● ●● ● ● ● ●● ●●● ● ● ● ●● ● ● ● ● ●● ●● ● ● ●● ● ● ● ● ● Brian ● ● ●● ● ● ●● ●●● Kenneth ● ● ● ●● ●● ● ●●● ● ● ● Harold ● ●●● ● ●● ● ● ● ●● ● ●● Walter ● ●●●● ● ●● ●●● ● ●● ● ●●● ●●● ●●● ●● ● ● ● ● ●● ● Arthur ● ●●●●● ●●● ●● ●● ● ● ● ●●● ● ●●● ● ● ● ● Matthew ●● ● ● ● ● ● ● ● ● ● George ● ●●● ● ●●●●●●●● ●●●● ● ●● ● ●●●● ● ●● ●●●● ●● ●● ●● ●● ● ● ● ●● ● ●● Kevin ● ●● ● ● ● ●● ● ● Christopher ● ●● ● ● ●● ● ● ● ●● ● ● ● ● ● ●● ● ● ●● Jack ●●●●●●●● ● ● ●● ● ● ● Henry ●● ● ●●● ●●● ●● ●● ●● ●● ● ● ●●●● ● ● ●●●● ● ● ●● ● ●●●● ● ● ● ●● ● ● ● ● Fred ● ● ● ●● ●●● ●●●●● ●● ●● Jason ●●●●● ● ● ●● ● ● ● ● ● Joshua ● ●●● ● ● ●● ● Eric ● ●● ● ● ● ● ●● ● ● reorder(name, lratio, na.rm = T) Daniel ●● ●● ● ● ●●● ● ●●●● ● Anthony ●●● ●●● ● ● ●● ● ●● ●● ● Louis ●● ● ●●● ●● ● ● ● ●● ● ● ●● ● ● ● ● Joe ●●●●● ● ● ● ●● ●●● ●● ● ● ●● ●● ●●●●● ●●●● ● ● ● ● ● ●●●● ●● ●● ● ● ●● ●● ● ● ● ● ● ● ●● Ryan ●● ● ● ● ●●● ● ●● ● ● ●● ● ● ●● ● ● ● ●● ● ● ●● Jerry ●●● ● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●●●● ● ● ●● ● ●● ●● ● ● ●● ● ● ●● ● ● ●●● ● ● ●● ● ●● Willie ●●● ●●●●●●●● ●● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ●●●●●●● ● ●●●●● ●●● ● ● ● ● ●● ● ● ●●● ●● ●● ● ● ●● ● ● ●●● Shirley ● ●● ● ● ● ● ● ● ● ●●● ● ● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●● ● ●●●● ● ● ● ● ●●● ● ● ● ●● ● ● ● ● ● ● Ashley ●● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● Carol ● ● ●●● ● ● ● ●● ● ● ●●● ● ● ● ● ● ●● ● ● ● ● ●● ●● ● ● ● ● ● ● ● ● ● ● ● ●●● ●● ● ● ● ● ● ● ●● ● Frances ● ●● ●●● ●● ●● ●●●● ●●●● ●● ● ●● ●● ●● ●● ● ● ●●● ● ●● ● ● ●● ●● ● ● ●● ● ● ● ●● Julia ● ● ● ● ● ●●● ● ●● Doris ● ●● ● ● ● ● ●● ●●●●●●●● ● ● ●● ●●● ● ●● ● ●● ● ● Irene ● ● ● ●● ● ● ● ●● ●● Louise ●● ● ●●● ●● ● ● ●●● ● ●● ● ● ●● ● ● ●● ● ● Rose ● ●●● ●● ● ●●●● ● ●● ● ●●●● ● ●● ● ●● Florence ●●● ● ● ● ●●● ● ●● ● ●● ●●● ●● ●● ●● ● ●●● Ethel ● ●●● ●●● ●● ●●● ●●● ● ● ● ●●●● ● ● ● ●● ● ● Edith ● ●●● ● ●●● ● ●● ● ● ● ●● ● Kimberly ● ●● ● ● ● ● ● ● ● ● ●● ●● ●● ● ● ● Annie ●● ● ●●● ●● ●● ● ● ● ● ● ●● ● ●● ●● ●● ● ●● ● ●● ● ● Edna ● ●●●●●● ●●● ● ●● ● ● ●● ● ● ● ● Minnie ●●● ●●● ● ●●● ● ● ● ●● ●● ● ● ●● ●● ● Grace ● ●● ● ● ●●● ● ●●● ● ● ●● ● ●● ● Clara ● ● ●●●● ● ●● ●● ● ●● ● ● ● ●●● ● ●● Bertha ●● ● ● ●●●● ● ● ● ● ● ●● ● ● ● ● ● ●● ● Lillian ● ● ● ● ●●●●● ●● ●● ● ● ● ● ● ● ●● ● ● ● Martha ●● ● ●● ● ●● ● ●● ● ● ●●● Marie ● ● ●● ● ●● ●●●● ● ●● ● ● ● ● ●● ● Emma ● ● ●●● ● ● ● ● ● ● ●● ● ● ● ●● ● ●● ● ●● Mildred ●● ● ●● ● ● ● ● ● ●● ●● ● ● ● ●● ● ● ● Alice ● ● ●●● ● ● ●●● ●●● ● ● ●● ● ●● ● ●● ● ●● ●● ● ● Anna ● ● ●●●● ●●●● ●● ●● ● ●●●● ●●● ● ● ● ● ●● ● ● ● ● Sarah ● ● ● ● ● ● ● ● ● ●● ● ●●● ●● ● ● Elizabeth ● ● ● ●● ●● ●● ● ● ● ● ●● ● ● ●● ● ● ●●●● ● ● ● ● ● ● ●● ●●●● ● ● ● ●● ● Ruth ● ● ●● ● ●● ●● ●● ●● ●● ●● ●● ● ● ●● ●● ●● ●● ● ● ●● ● ● ● ● ● Margaret ●●● ●●● ●● ● ●●● ● ● ●● ●● ●●● ● ●● ● ●● ● ● ● ● ● ● ●●● ● ● ●● ●● ●●● ●● ● Helen ● ●● ● ●●● ●● ●● ●●● ● ●● ● ● ● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● ● ●● ● ● ● Virginia ●●●●● ● ● ● ●● ●● ● Dorothy ● ● ● ● ● ●● ● ●●● ●● ●● ● ● ●● ● ● ● ● ● ● ●● ● ●● ●● ● ●● ●● ● ● Mary ●●●● ●●● ●●●●●●●●● ●●●●● ●●● ●●●● ●● ●●●●●●● ●● ●●● ● ●● ●● ●●● ● ● ● ● ● ●●● ●●● ● ●● ● ● ●● ● Betty ● ● ● ● ● ● ● ●●● ● ●● ● ●● ● ● ●● ● ● Michelle ● ●●● ● ● ● ● ●●● ● ● ●● Sharon ● ● ● ● ●●● ● ● ● ●● ●● ● ● ● Jessica ● ● ● ●● ● ● ●● ● Melissa ● ● ● ●●● ● ●● ● ● ●●●● Nancy ● ●● ●● ● ●● ●● ● ● ● ● ●● ● Jennifer ● ● ●●● ●●● ● ●●●● ● ●● ● ● ●● Amanda ●● ●● ●● ●● ●● ● ● Patricia ● ●●●● ● ●●●●●●● ● ●●● ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● Donna ● ● ● ● ●●● ● ● ● ● ●● ● Sandra ●● ● ● ● ● ● ● ● ● ●● ● ● Barbara ● ● ● ●● ● ● ●● ● ● ● ● ● ● ● ● ● ●● ● ●● ● ● Lisa ● ● ● ● ● ●● ● ● ●● ● ● ● Karen ● ● ●● ● ● ● ●● ● ● ● ● ●● ● ● Linda ● ● ● ●● ● ●●● ● ●● ●● ● ● ● ●●● ● ●● ● Susan ● ● ● ● ● ● ● ● ●● ● ● ● ● ● ● ● ● ●● ● 0.5 1.0 1.5 2.0 2.5 abs(lratio) Wednesday, 7 October 2009
    • theme_set(theme_grey(10)) qplot(year, lratio, data = bysex, group = name, geom = "line") qplot(lratio, reorder(name, lratio, na.rm = T), data = bysex) qplot(abs(lratio), reorder(name, lratio, na.rm = T), data = bysex) qplot(abs(lratio), reorder(name, lratio, na.rm = T), data = bysex) + geom_point(data = both_sexes, colour = "red") Wednesday, 7 October 2009
    • 2 1 0 lratio −1 What characteristics of −2 each name might we want to use to classify them into dual-sex with sex-errors? 1880 1900 1920 1940 1960 1980 2000 year Wednesday, 7 October 2009
    • Your turn Compute the mean and range of lratio for each name. Plot and come up with cutoffs that you think separate the two groups. Wednesday, 7 October 2009
    • rng <- ddply(bysex, "name", summarise, diff = diff(range(lratio, na.rm = T)), mean = mean(lratio, na.rm = T) ) qplot(diff, abs(mean), data = rng) qplot(diff, abs(mean), data = rng, colour = abs(mean) < 1.75 | diff > 0.9) shared_names <- subset(rng, abs(mean) < 1.75 | diff > 0.9)$name qplot(abs(lratio), reorder(name, lratio, na.rm=T), data = subset(bysex, name %in% shared_names)) qplot(year, lratio, geom = "line", group = name, data = subset(bysex, name %in% shared_names)) Wednesday, 7 October 2009
    • Next time Now that we’ve separated the two groups, we’ll explore each in more detail. Wednesday, 7 October 2009