PDB_Stat_100_Lecture_06

# PDB_Stat_100_Lecture_06 - STA 100 Lecture 6 Paul Baines...

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

STA 100 Lecture 6 Paul Baines Department of Statistics University of California, Davis January 14th, 2011

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

View Full Document
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 ).
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.)

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

View Full Document
Some R Tips/Tricks You need two things to complete the R portion on Hwk 2: sampling and subsetting .
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 == .

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

View Full Document
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...
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

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

View Full Document
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
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! ,

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

View Full Document
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.
SRS vs. Cluster Sampling Recall: I SRS: Everyone has same chance of being picked.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern