Title

For all of the questions below incorporate the necessary R code directy into your answers.

The Iowa Department of Natural Resources monitors water quality in different sites across Iowa and provides access to these records at [http://programs.iowadnr.gov/iastoret/srchStations.aspx]

Data on a variety of different analytes for several sites in the Big Creek area (local lake) are given in the data set [http://www.hofroe.net/stat579/data/bigcreek.csv]

### Question 1

(25 pts) Is the data set in a normal form? Start your assessment with the 3rd normal form and work downwards. For each normal form that you reject give an example from the dataset that does not violate the lower normal form. Don’t forget to include in your discussions which (combination of) variable(s) form(s) (part of) the key.

For each of the counter examples describe, how you can bring the data into normal form. Start from the lowest normal form. Note: there might be more than one reason why a form is not in normal form. It is enough to fix one of the problems. In each example, first describe in words how you want to solve the problem, then show the code.

### Question 2

(25 pts) Identify the analyte for which most observations are available. Create a data frame summary.stat for an overview of this analyte by station, which includes

• the number of observations,
• the percentage of results (Result) not equal to zero,
• and basic summaries of the results (Result), including mean, maximum, minimum, and standard deviation of the records.

The data set [http://www.hofroe.net/stat579/data/stationsinfo.csv] contains information on each station at which observations are taken. Merge this information with the summary.stat data. Draw a scatterplot of the mean observed values (as color) by longitude and latitude.

Split variable Date_Time into two variables, separating date and time of the day. For the last three years in the data, plot recorded values for the above analyte over time, colour by station. Describe your findings.

### Question 3

(25 pts) Write a function ‘trim’ that computes the mean of a numeric vector x after removing a percentage p of the most extreme values (both large and small values with respect to the mean). In the function first determine the number of values to remove, then remove one value at a time. Make sure to type check, also test for and deal with missing values appropriately.

At the example of the water quality data find the mean result of pH with and without trimming 5% of the data. For which analyte do the untrimmed mean and a 5% trimmed mean ‘differ’ the most? Discuss why the absolute difference is not the most appropriate choice. Suggest a more suitable ‘difference’.

Note: if you can’t get the function trim to work, use the regular mean and investigate the purpose of the parameter trim. Caution: even if you got your function to work, the results of trim and mean will be different.

(25 pts) For the following gene sequence write a single regular expression that allows to “bundle” sequences of length 10 by inserting a white space. Use the expression in an appropriate R function on the sequence below to re-format the sequence.

Extend your code to a function bundle (x, k=10) that allows to produce bundles of length k. Run your function for k=3 on the sequence below.

sequence <-
"ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGGCCACGGCCACCGCTGCCCTGCCCCTGGAGGGTGGCCCCACCGGCCGAGACAGCGAGCATATGCAGGAAGCGGCAGGAATAAGGAAAAGCAGCCTCCTGACTTTCCTCGCTTGGTGGTTTGAGTGGACCTCCCAGGCCAGTGCCGGGCCCCTCATAGGAGAGGAAGCTCGGGAGGTGGCCAGGCGGCAGGAAGGCGCACCCCCCCAGCAATCCGCGCGCCGGGACAGAATGCCCTGCAGGAACTTCTTCTGGAAGACCTTCTCCTCCTGCAAATAAAACCTCACCCATGAATGCTCACGCAAGTTTAATTACAGACCTGAA"