0% found this document useful (0 votes)
15 views3 pages

Bsta 3152 Practical 2

Uploaded by

jumajohn0013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Bsta 3152 Practical 2

Uploaded by

jumajohn0013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

BSTA 3152

THE COOPERATIVE UNIVERSITY OF KENYA


PRACTICAL TEST
EXAMINATION FOR BACHELOR OF SCIENCE IN APPLIED STATISTICS AND
BACHELOR OF SCIENCE IN ACTUARIAL SCIENCE
COURSE CODE: BSTA 3152
UNIT TITLE: STATISTICAL PROGRAMMING
DUE DATE: 3RD DECEMBER 2024 (1400 HRS) Time: 1 HR

INSTRUCTIONS
1. AnswerALL questions
2. Write clear well commented codes.
3. Knit a html file or word converted to pdf for your task.
4 Upload your work on the Emasomo link before the due date provided.
NB:Any task sent after the time has lapsed will attract a score of 0(ZERO).

PRACTICAL TASK (40 MARKS)


1. Create a new rmd file: Name: Practical cat 2:::: Author: your name-reg no.

2. R chunk 1: Consider the Bank.csv data file provided for you. Use the data to perform
the following tasks.

(a) Load the dataset into r environment and name it bank


(b) Display the first 5 rows of bank dataset.
(c) Display the last 5 rows of the dataset.
(d) Generate summary statistics of the data variables.
(e) Output the dimension of the dataset.
(f) Convert the ”Gender” variable to a categorical variable.

3. R chunk 2: Consider the set of data 3, 0, 8, 4, 3, 5, 9, 5, 7, 10, 6, 3.

(a) Input the data into R and form a 3 × 4 matrix named Matrix1.
(b) Output the first row of Matrix1.

The Co−operative University of Kenya−3RD DECEMBER 2024 (1400 HRS) 1


BSTA 3152

(c) Output the element in the 2nd row and 3rd column.
(d) Find the inverse of Matrix1.

4. R chunk 3: Using the data below, perform the following task writing well-commented
codes:
Table 1: Student Performance Data

Gender Race Lunch Prep Course Statistics Score Reading Score Writing Score
Female Group B Standard None 72 72 74
Female Group C Standard Completed 69 90 88
Female Group B Standard None 90 95 93
Male Group A Free None 47 57 44
Male Group C Standard None 76 78 75
Female Group B Standard None 71 83 78

(a) Input the data into R environment and outputs the table.
(b) Output the first 5 rows of the data.
(c) Filter observations for female students.
(d) Sort the observations using the Statistics Scores in ascending order and Reading Scores
in descending order.
(e) Create a new column titled âTotal Scoreâ that calculates the total score for each student
in the three subjects.
(f) Performs correlation between Statistics score and Writing Score and plots a Scatter
plot of the two variables.
(g) Plot a histogram of the Statistic Score

5. R chunk 4: Given the following system of linear equations:

5p + 2q − r = 5
p − 4q + 5r = −1
2p + q + 3r = 10

Write well-commented R codes that does the following:

(i). Represent this system as a matrix A and a vector b.


(ii). Displays the matrix equation Ax = b.
(iii). Solves the system of equations and outputs the solution.

6. R chunk 5: Write a function in R that accepts a vector of numbers and returns product,
mean and variance of the vector.

The Co−operative University of Kenya−3RD DECEMBER 2024 (1400 HRS) 2


BSTA 3152

2
7. R chunk 6: Consider the following function f (x) = x cos(x)+2xsin(x)
x4 +cos(x)
. Write well commented
R codes to find the integral of the function where 2 ≤ x ≤ 4.

8. R chunk 7: Use R to find the second derivative of f (x) = x4 − 3x3 + 2x2 with respect to
x. Write a well commented R code to compute and display the second derivative.

The Co−operative University of Kenya−3RD DECEMBER 2024 (1400 HRS) 3

You might also like