Sampling
1 Introduction
Continuing to treat the NHANES
dataset as a
population, We will try to replicate the process of
sampling and CLT for another variable in the NHANES variable,
AlcoholYear
.
1.1 Summary for
AlcoholYear
population
# Summary of `alcohol-year`
#
1.2 Sampling
AlcoholYear
# Sampling `alcohol-year`
# Varying samples size and sample count
#
1.3 Distribution and QQ Plot for the sample
# qq-alcohol-year
#
#
1.4 Estimating Population Mean and Confidence Interval using the Sample
# mean and confidence intervals for various sample sizes
1.5 Case Study #2
Let us look at video game data from the University of Berkeley {Stats Lab](
library(tidyverse)
<- read_csv("./data/video-data.csv")
video_games ::inspect(video_games) mosaic
##
## categorical variables:
## name
## 1 time like where freq busy educ sex age home math work own cdrom email grade
## class levels n missing distribution
## 1 character 91 91 0 (%) ...
Variable | Description |
---|---|
time | Time spent playing video games in week prior to survey in hours. |
like | Like to play video games 1=Never played, 2=Very much, 3=Somewhat, 4=Not really, 5=Not at all |
where | Where play video games 1=Arcade, 2=Home on a system, 3=Home on a computer 4=Home on computer and system, 5=Arcade and Home(system or computer) 6=Arcade and home (both system and computer) |
freq | How often play video games 1=Daily, 2=Weekly, 3=Monthly, 4=Semesterly |
busy | Play if busy 0=no, 1=yes |
educ | Is playing video games educational? 0=no, 1=yes |
sex | Sex 0=female, 1=male |
age | Age in years |
home | Computer at home 0=no, 1=yes |
math | Hate math 0=no, 1=yes |
work | Hours worked for pay in the week prior to survey |
own | Own PC 0=no, 1=yes |
cdrom | Owned PC has a CDROM 0=no, 1=yes |
HAve email account 0=no, 1=yes |
|
grade | Grade expect in course 4=A, 3=B, 2=C, 1=D, 0=F |
1.6 Sampling
time
1.7 Distribution and QQ Plot for the sample
1.8 Estimating Population Mean and Confidence Interval using the Sample
1.9 Conclusion
Write up some comments here on your learnings on:
- Sampling - CLT
LS0tDQp0aXRsZTogIlNhbXBsaW5nIg0KYXV0aG9yOiAiQXJ2aW5kIFZlbmthdGFkcmkiDQpkYXRlOiAyMDIzLzEvMTENCmxhc3Rtb2Q6ICdgciBTeXMu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AgICAgICAgICAgICAgICAgfA0KKz09PT09PT09PT09PSs9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PSsNCnwgwqB0aW1lICAgICAgfCDCoFRpbWUgc3BlbnQgcGxheWluZyB2aWRlbyBnYW1lcyBpbiB3ZWVrIHByaW9yIHRvICAgICAgIHwNCnwgICAgICAgICAgICB8IHN1cnZleSBpbiBob3Vycy4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8DQorLS0tLS0tLS0tLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKw0KfCDCoGxpa2UgICAgICB8IMKgTGlrZSB0byBwbGF5IHZpZGVvIGdhbWVzXCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA0KfCAgICAgICAgICAgIHwgwqAxPU5ldmVyIHBsYXllZCwgMj1WZXJ5IG11Y2gsIDM9U29tZXdoYXQsIDQ9Tm90ICAgICAgICB8DQp8ICAgICAgICAgICAgfCByZWFsbHksIDU9Tm90IGF0IGFsbCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA0KKy0tLS0tLS0tLS0tLSstLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSsNCnwgwqB3aGVyZSAgICAgfCDCoFdoZXJlIHBsYXkgdmlkZW8gZ2FtZXNcICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwNCnwgICAgICAgICAgICB8IMKgMT1BcmNhZGUsIDI9SG9tZSBvbiBhIHN5c3RlbSwgMz1Ib21lIG9uIGEgY29tcHV0ZXIgICAgfA0KfCAgICAgICAgICAgIHwgND1Ib21lIG9uIGNvbXB1dGVyIGFuZCBzeXN0ZW0sIDU9QXJjYWRlIGFuZCAgICAgICAgICAgIHwNCnwgICAgICAgICAgICB8IEhvbWUoc3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LS0tLS0tLS0tLS0tLS0tLS0tLSsNCnwgwqBzZXggICAgICAgfCDCoFNleFwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwNCnwgICAgICAgICAgICB8IMKgIDA9ZmVtYWxlLCAxPW1hbGUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA0KKy0tLS0tLS0tLS0tLSstLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLSsNCnwgwqBhZ2UgICAgICAgfCDCoEFnZSBpbiB5ZWFycyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwNCistLS0tLS0tLS0tLS0rLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0rDQp8IMKgaG9tZSAgICAgIHwgwqBDb21wdXRlciBhdCBob21lXCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8DQp8ICAgICAgICAgICAgfCDCoCAwPW5vLCAxPXllcyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwNCistLS0tLS0tLS0tLS0rLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0rDQp8IMKgbWF0aCAgICAgIHwgwqBIYXRlIG1hdGhcICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8DQp8ICAgICAgICAgICAgfCDCoCAwPW5vLCAxPXllcyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwNCistLS0tLS0tLS0tLS0rLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0rDQp8IMKgd29yayAgICAgIHwgwqBIb3VycyB3b3JrZWQgZm9yIHBheSBpbiB0aGUgd2VlayBwcmlvciB0byBzdXJ2ZXkgICAgICB8DQorLS0tLS0tLS0tLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKw0KfCDCoG93biAgICAgICB8IMKgT3duIFBDXCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA0KfCAgICAgICAgICAgIHwgwqAgMD1ubywgMT15ZXMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8DQorLS0tLS0tLS0tLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKw0KfCDCoGNkcm9tICAgICB8IMKgT3duZWQgUEMgaGFzIGEgQ0RST01cICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA0KfCAgICAgICAgICAgIHwgwqAgMD1ubywgMT15ZXMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8DQorLS0tLS0tLS0tLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKw0KfCDCoGVtYWlsICAgICB8IMKgSEF2ZSBlbWFpbCBhY2NvdW50XCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA0KfCAgICAgICAgICAgIHwgwqAgMD1ubywgMT15ZXMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8DQorLS0tLS0tLS0tLS0tKy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tKw0KfCDCoGdyYWRlICAgICB8IMKgR3JhZGUgZXhwZWN0IGluIGNvdXJzZVwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfA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