Question: Programming Assignment 1 STAT 311 All points available are visible. Remember: Do not rename provided data files or edit them in any way. Do not
Programming Assignment 1 STAT 311 All points available are visible. Remember: Do not rename provided data files or edit them in any way. Do not use global paths in your script. Instead, use setwd() interactively in the console, but do not forget to remove or comment out this part of the code before you submit. The directory structure of your machine is not the same as the one on Gradescope's virtual machines. Do not destroy or overwrite any requested variables in your program. I check them only after I have run your entire program from start to finish. Check to make sure you do not have any syntax errors. Reset the working environment and rerun your entire assignment to ensure it runs without errors using the source command. Make sure to name your submission STAT311-HW1.R Note that the autograder does not allow for use of tidyverse or tidyverse code - code that LLMs love to produce. Overview We will be looking at the county dataset from the usdata package that looks at a number of variables for US counties. You will need to install the package using install.packages("usdata") exactly once. You can import the package with library(usdata) each time you start RStudio or clear the workspace. Part 1 Treating the county dataset as the population of US counties, create the dataframe my.SRS that samples from county and represents a simple random sample of n = 250 individual counties from all counties in the US. 1
Part 2 Treating the county dataset as the population of US counties create the dataframe my.Stratified that represents a stratified sample of individual counties from all counties in the US, statified along the level of education using the median edu variable. Due to the different sizes of strata, you should sample: 1 county from below hs 140 from hs diploma 170 from some college 4 from bachelors Part 3 Treating the county variable as a population of US counties create the dataframe my.Clustered that represents a cluster sample of individual counties from all counties in the US, clustered by state using the state variable. You should randomly sample all counties from a total of 5 clusters. 2
# You will be using the "usdata" package's "county" data
# for this assignment.
# You will need to run:
# install.packages("usdata")
# once to install this library - do not include the
# install.packages command in your submission
# as it can cause gradescope to fail
## ## ## ## ## DO NOT MODIFY BELOW ## ## ## ## ##
library(usdata)
county<-as.data.frame(county)
county<-county[,1:14]
county<-county[rowSums(is.na(county))==0,]
# The set.seed command will ensure your results are consistent
# each time you run the "source" command
set.seed(311)
## ## ## ## ## DO NOT MODIFY ABOVE ## ## ## ## ##
# Treating the "county" dataset as the population of US counties
# create the dataframe "my.SRS" that represents a simple
# random sample of n=250 individual counties from all counties in the US.
my.SRS <- NA
# Treating the "county" dataset as the population of US counties
# create the dataframe "my.Stratified" that represents a stratified
# sample of individual counties from all counties in the US, statified
# along the level of education (median_edu). Due to the different sizes of strata,
# you should sample:
# 1 county from "below_hs", 140 from "hs_diploma", 170 from "some_college"
# and 4 from "bachelors"
my.Stratified <- NA
#The numbers here should match those specified above
# Uncomment after your data frame has been defined to check your work
# table(my.Stratified$median_edu)
# Treating the "county" dataset as the population of US counties
# create the dataframe "my.Clustered" that represents a cluster
# sample of individual counties from all counties in the US, clustered by state.
# You should randomly sample counties from a total of 5 clusters.
my.Clustered <- NA
#This should only give 5 total states
# Uncomment after your data frame has been defined to check your work
# unique(my.Clustered$state)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
