Assignment 1
Assignment 1
Assignment 1
General Instructions:
You must create a R Script/file by the name “YourName_Assignment-1”. Send me the file
along with a pdf copy of the codes. The graphs must be saved as different files and sent to
me along with the assignment.
Please do not copy. You are free to discuss among yourselves but each one of you must write
your own code and send it to me.
You must interpret the results in Part II. The R script that you send should run on my laptop
as it is.
1. Create a vector named GMP. The size of the vector should be 10 and the elements in
the vector are multiples of 7 starting from 21.
2. Randomly select 5 numbers from the vector. Repeat the process 5 times and name
them GMP_vector_i, where i refers to the sample number. Create a matrix
GMP_matrix by combining these vectors. Name the rows as Student_i, where I refers
to the row number.
3. Transpose the matrix, find the inverse of the matrix and also the product of the
principal diagonal elements.
4. Create two matrices named Row Matrix and Column Matrix. The elements of these
matrices are the GMP_matrix elements sorted row-wise and column-wise respectively.
5. Compute the column-wise and row-wise mean and variances for the GMP_matrix.
6. Plot the means obtained above. (Use Scatter-Plot and Bar Charts with appropriate
names). Also create two pie-charts (one each for Column Mean and Row-mean).
7. Transform the elements in the GMP_matrix using the following transformation:
𝑓 (𝑥) = λ * e-λ / x!
Consider the dataset Women. Name the columns as Height and Weight respectively.
Check whether the mean height =65 and mean weight =115. Also check if the
variance of height and weight are same.
Perform a linear regression with Weight as the dependent variable. Name the
regression object as Regress. Carry out the regression diagnostics.
Create prediction intervals (90, 95 and 99%) and plot them along with the best fit line.
Create a new variable HSquare= Height2. Repeat the regression now using two
independent variables Height and HSquare.
Use forward and backward regression to arrive at the best model.