Docsity

Homework 4 - Computing in Statistics - Fall 2007 | 22S 166, Assignments of Statistics

Toggle sidebar
bg1
22S:166 Fall 2007
Instructor: Cowles
Homework 4
See reading assignment under Web Resources on course web page.
Problems (due Fri. 9/28):
1. In R, use the help.search function to locate a package that contains a
function to compute the skewness of a vector of numbers. What is the
name of the function, and which package is it in?
2. Locate an R function that computes the five-number summary of a vector
of numbers. What is the name of the function, and which package is it
in?
3. Write an R function that does the following:
(a) Accepts one argument: a vector
(b) Checks whether the vector is numeric
(c) If not, displays the message “Vector must be numeric” and exits
(d) If yes, computes the skewness of the values (after removing any miss-
ing values)
i. if the absolute value of skewness is less than 1, returns a list
containing two objects:
A. skewness in an object named “skewness”
B. a vector consisting of the mean and standard deviation in an
object named “descstats”
ii. otherwise, returns a list containing two objects
A. skewness in an object named “skewness”
B. a vector consisting of the five-number summaryin an object
named “descstats”
4. Run your function in R three times, using the following vectors as argu-
ments:
(a) c(”Arthur”, ”Mary”, ”Rover”)
(b) rnorm( 100 )
(c) rexp( 100, 5)
Submit your homework electronically through ICON by Fri. 9/28. Include
a text file with all your R code, as well as a PDF file that has
1. answers to questions 1 and 2
2. a listing of your function
1
3. the command lines and output from your three calls to your function
Your output ought to look something like the following (with different nu-
meric values):
> mydesc( rnorm(100) )
$skewness
[1] 0.1931722
$descstats
[1] -0.03160733 0.94527957
> mydesc( rexp(100,5) )
$skewness
[1] 1.462030
$descstats
[1] 0.000019662 0.057816812 0.105732124 0.265288314 0.806777159
2

Partial preview of the text

Download Homework 4 - Computing in Statistics - Fall 2007 | 22S 166 and more Assignments Statistics in PDF only on Docsity!

22S:166 Fall 2007Instructor: Cowles

Homework 4

See reading assignment under Web Resources on course web page.Problems (due Fri. 9/28):1. In R, use the

help.search

function to locate a package that contains a

function to compute the skewness of a vector of numbers.

What is the

name of the function, and which package is it in?

  1. Locate an R function that computes the five-number summary of a vector

of numbers.

What is the name of the function, and which package is it

in?

  1. Write an R function that does the following:

(a) Accepts one argument: a vector(b) Checks whether the vector is numeric(c) If not, displays the message “Vector must be numeric” and exits(d) If yes, computes the skewness of the values (after removing any miss-

ing values)

i. if the absolute value of skewness is less than 1, returns a list

containing two objects:A. skewness in an object named “skewness”B. a vector consisting of the mean and standard deviation in an

object named “descstats”

ii. otherwise, returns a list containing two objects

A. skewness in an object named “skewness”B. a vector consisting of the five-number summaryin an object

named “descstats”

  1. Run your function in R three times, using the following vectors as argu-

ments:(a) c(”Arthur”, ”Mary”, ”Rover”)(b) rnorm( 100 )(c) rexp( 100, 5) Submit your homework electronically through ICON by Fri. 9/28. Include a text file with all your R code, as well as a PDF file that has

  1. answers to questions 1 and 22. a listing of your function
  1. the command lines and output from your three calls to your functionYour output ought to look something like the following (with different nu- meric values): > mydesc( rnorm(100) )$skewness[1] 0.1931722$descstats[1] -0.

mydesc( rexp(100,5) )$skewness[1] 1.462030$descstats[1] 0.000019662 0.057816812 0.105732124 0.265288314 0.