Department of Statistics
STATS 390 Summer Semester 2009
Assignment 1
Due: 12 January 2009
Please answer all questions.
You have only till next Monday to have this done so get on
it TODAY!
1.
[6 mark(s)] Make the following
R
functions and record
R
output in your word document
(a) [2 mark(s)] A function that calculates the area of a triangle of base length
b
and height
h
. Call
the function
triarea(b,h)
calculate
triarea(b=2,h=4)
and record the result with the above code
(b) [2 mark(s)] A function that calculates the perimeter of a circle of radius
r
. Call it
circleper(r)
calculate
circleper(r=20)
and record the result with the above code
(c) [2 mark(s)] A function that plots a quadratic equation with y the vertical axis and x the
horizontal. Use the
curve()
command with x taking values between 10 and 10. Call it
myquad(a,b,c)
where the a, b, and c correspond to
y
=
ax
2
+
bx
+
c
calculate
myquad(a=1,b=5,c=6)
and record the result with the above code
and plot
2.
[6 mark(s)] We often need to make up random variables by simulation, some distributions have
already been prepackaged in
R
(like
rnorm()
) and we will now use one or two of them.
(a) [2 mark(s)] Make a function that produces
n
values from a
N
(
mean
= 10
, sd
= 5) distribution.
Call it
mynorm(n)
where
n
is the number of samples from
N
(
mean
= 10
, sd
= 5)
Calculate
mynorm(n=10)
and record the answer with the function code.
(b) [2 mark(s)] Make a new function that plots a histogram of normal values where the mean and
sd are variables with n. Call it
STATS 390 Summer Semester 2009
Assignment 1
Page 1 of 3
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
mynormhist(n,mn,std)
where
n
is the number of samples from
N
(
mean
=
mn, sd
=
std
)
Submit
mynormhist(n=200,mn=2,std=5)
and record the plot with the function code.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 renate
 Statistics, WinBUGS

Click to edit the document details