The stateriskapp function should do the following:
(a) Find out the number of observations that the survey contains for the state, the rival state and
the whole survey. Use the scan function to report them to the computer screen.
(b) Determine whether the variable imonth, iyear and iday contain some strange observations
(something not possible, like iday=40, for example). There are no months with 40 days. The
function should make those NA.
(c) Create a dataset call my.subset with only observations for the state and the rival state.
The data set should contain only these variables: STATE, IDAY, IMONTH, IYEAR
,WEIGHT, WTDESIRE, GENHLTH, MEDCOST, DIABETES, POTATOES, LOSEWT,
EXERANY, AGE, MARITAL, EDUCA.
Use the codebook online to label the codes of the variables that are categorical. Make sure
that those variables are factors.
(d) Convert none, don’t know, refused coding and other strange coding that may confuse the
results into NA if the variable is numerical. Not needed for the categorical, as those codes
are categories as well.
(e) Create a variable called GAPWEIGHT representing the difference between how much the
person weighs and how much the person desires to weigh. Include that variable in the
dataframe. Using cat() report to the screen how much that difference is. The state needs this
variable to see if it needs to create interventions to have an indicator of how happy people
(f) Compare the weight of people with diabetes and without diabetes using boxplots and also
using summary statistics such as the mean and median.Report the mean for diabetics and
nondiabetics using cat(). The state is doing this to see if it should start a public campaign to
promote weight reduction among diabetics, where overweight is a risk factor.
(g) Conduct a t-test to determine whether the people of the sate have higher gapweight than
those in the rival state. Your function should give a comment saying the conclusion of the ttest
such as “there is or there is not significant difference and the difference is….” (give a
value for the difference. Use cat() to do that.
(h) Do a t.test to determine whether the weight in the state is significantly different from the
weight for all the nation, as represented by the whole suvey data. Write to the screen with
cat() comments indicating the conclusion of the test. This information is important to
determine whether people in the state are or are not more overweight than the ones in the