PDB_Stat_100_Lecture_06

PDB_Stat_100_Lecture_06 - STA 100 Lecture 6 Paul Baines...

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
STA 100 Lecture 6 Paul Baines Department of Statistics University of California, Davis January 14th, 2011
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Admin for the Day I Homework 2 posted, due Wednesday, Jan 19th in class I NO CLASS MONDAY – MLK DAY! I Comments: In the math and statistics world, log always means natural log i.e., log e or ‘ln’ as you may have seen previously. e.g., log(animals body) will give the (natural) log brain weights. ( ln doesn’t exist in R ).
Image of page 2
Admin for the Day I Homework 2 posted, due Wednesday, Jan 19th in class I NO CLASS MONDAY – MLK DAY! I Comments: In the math and statistics world, log always means natural log i.e., log e or ‘ln’ as you may have seen previously. e.g., log(animals body) will give the (natural) log brain weights. ( ln doesn’t exist in R ). References for Today: Rosner, Ch 3.7-3.8 (7th Ed.) References for Wednesday: Rosner, Ch 4.1-4.9 (7th Ed.)
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Some R Tips/Tricks You need two things to complete the R portion on Hwk 2: sampling and subsetting .
Image of page 4
Some R Tips/Tricks You need two things to complete the R portion on Hwk 2: sampling and subsetting . I Subsetting Data: Point-and-click via: Data > Active Dataset > Subset active dataset Choose a logical (T/F) subset expression . For example: animal == "Cow" Give your subset a different name! Note the double == .
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Subsetting Data by Hand I Manually Subsetting Data: Simple examples: > animals[1,] # show the first row > animals[1:5,] # Show the first 5 rows > animals[,"brain"] # show the "brain" column A more sophisticated example: > # Pick only those animals whose body size > # is bigger than the median body size > x.med <- median(animals$body) > subby <- animals[animals$body > x.med, ] > subby animal body brain 2 Cow 465.0 423.0 6 Dipliodocus 11700.0 50.0 ...etc...
Image of page 6
Random Samples in R I Sampling in R : You can sample from a list of values in R using the sample function: > x <- c(1:10) # x = (1,2,3,4,5,6,7,8,9,10) > # Randomly pick 4 values from x > first.one <- sample(x,4) > second.time <- sample(x,4) # do it again... > first.time [1] 3 6 1 4 > second.time [1] 1 2 3 8 > animals[first.time,] animal body brain 3 Grey wolf 36.33 119.5 6 Dipliodocus 11700.00 50.0 1 Mountain beaver 1.35 465.0 4 Goat 27.66 115.0
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Putting it together I We can now randomly pick which rows to keep, and we know how to pick out a subset of rows. Together: > # Randomly pick 4 of the 27 animals > animals[sample(1:27,4),] animal body brain 17 Rhesus monkey 6.8 179 23 Jaguar 100.0 157 2 Cow 465.0 423 15 African elephant 6654.0 5712
Image of page 8
Putting it together I We can now randomly pick which rows to keep, and we know how to pick out a subset of rows. Together: > # Randomly pick 4 of the 27 animals > animals[sample(1:27,4),] animal body brain 17 Rhesus monkey 6.8 179 23 Jaguar 100.0 157 2 Cow 465.0 423 15 African elephant 6654.0 5712 You will get a different answer each time! ,
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
SRS vs. Cluster Sampling Recall: I SRS: Everyone has same chance of being picked. I Cluster Sample: People are divided into clusters, then we pick some clusters, and then only pick people within those clusters.
Image of page 10
SRS vs. Cluster Sampling Recall: I SRS: Everyone has same chance of being picked.
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern