# Stat 432 Homework 1 solution

\$30.00

Original Work ?

5/5 - (1 vote)

## Question 1 (basic R)

Perform the following tasks on the iris dataset:
a. Change the class labels of the Species variable from setosa, versicolor and virginica to small,
median and large, respectively.

b. Change the variable name from Species to Size. Note that for both questions a) and b), you need to
change the original variable, not creating a new variable and replacing the old one.

c. Create a boxplot for the variable Petal.Length that shows different boxes for different levels of Size.
d. Use a linear model to estimate Petal.Length using all other four covariates. Report the coefficients
and the most significant variable.

## Question 2 (a simple optimization)

Consider a minimization problem with two arguments (the Rosenbrock function):
f(x1, x2) = (1 − x1)
2 + 100 × (x2 − x
2
1
)
2
a. Write an R function that takes a vector (of two elements) as the input and output the Rosenbrock
function value.

b. Finally, use the optim() function to find and report the minimizer.

c. (bonus) Write your own R code of coordinate descent algorithm to obtain the minimal solution. You
can choose either Gauss-Seidel or Jacobi implementation.