Anda di halaman 1dari 2

Programming and Statistics in R

Exercise 6
1. Test to see if the data sample

0.111 0.262 0.067 0.720 2.733 1.698 0.711 1.265 3.776 3.654

is consistent with an Exp(1) distribution using a QQ plot

plot(qexp(ppoints(x),1),sort(x))
abline(0,1)

2. Consider the Pima Indians data: a collection of variables observed on


a particular group of native American Indians who are either healthy
or diabetic. This data includes measurements of tricep skinfold and
blood glucose level.

pima.df <- read.csv("http://wwwf.imperial.ac.uk/nadams/pima.csv")


You may need to type out the symbol if you copy and paste the URL.
attach(pima.df)
plot(triceps,glucose,type="n")
points(triceps[class==0],glucose[class==0],xlab="Tricep",ylab="glucose")
points(triceps[class==1],glucose[class==1],xlab="Tricep",ylab="glucose",col=2,pch=2)

legend(40,50,c("Diabetes","Healthy"),pch=1:2)

3. Use lattice graphics to produce a similar picture.

Problems
1. Examine the built in ChickWeight data (the help gives background
about the data). The function split may prove useful to do the fol-
lowing (as will a script), or you can make use of the logic and selection
techniques.

(a) Construct a plot of weight against time for chick number 34.
(b) For chicks in diet group 4, display a box plot of the weights of
chicks at each time point. [use split]
(c) Compute the mean weight for chicks in group 4, for each time
point. Plot this mean value against time.
(d) Repeat the previous computation for group 2. Add the mean for
group 2 to the existing plot.

1
(e) Add a legend and a title.
(f) Copy and paste the graph into Word.

Note that some of these steps will be easier once we have some more
programming expertise.

Anda mungkin juga menyukai