Classwork1 Answer

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Term 2, 2021/2022

DSA211 Statistical Learning with R


Classwork 1 Answers
R Codes of Q1
#Q1
1:10
1:10*0.1
bb <- c(12, 15, 16, 19, 20, 24, 35, 14, 18)
bb[3]
bb[2:5]
length(bb)
length(bb[bb>16.5])

R Output of Q1
>#Q1
> 1:10
[1] 1 2 3 4 5 6 7 8 9 10
> 1:10*0.1
[1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
> bb <- c(12, 15, 16, 19, 20, 24, 35, 14, 18)
> bb[3]
[1] 16
> bb[2:5]
[1] 15 16 19 20
> length(bb)
[1] 9
> length(bb[bb>16.5])
[1] 5

1
Term 2, 2021/2022

Answer of Q1
a. Generate integers from 1 to 10
b. Generate 10 numbers from 0.1 to 1, each increased by 0.1
c. Generate a vector called bb;
Get the third element (16) of bb;
Get the second to fifth elements (15, 16, 19, 20) of bb;
Find the total number of elements (9) in bb;
Find the number of elements (5) in bb which is bigger than 16.5.

R Codes of Q2
parta <- ppois(8, 1.75*4)-ppois(3, 1.75*4)
partb <- dhyper(2,6,7,5) +dhyper(3,6,7,5)+ dhyper(4,6,7,5)+dhyper(5,6,7,5)
partc <- 1-pbinom(2, 25, 0.05)
parta
partb
partc

R Output of Q2
> parta
[1] 0.6473259
> partb
[1] 0.8205128
> partc
[1] 0.1271065

Answer of Q2
a. 0.6473
b. 0.8205
c. 0.1271

2
Term 2, 2021/2022

R Codes of Q3
ha <- pnorm(19000, 16500, 4800)-pnorm(18000, 16500, 4800)
hb <- qnorm(0.8, 16500, 4800)
pp <- 1-pnorm(18000, 16500, 4800)
hc <- pbinom(3, 12, pp)
ha
hb
hc

R Output of Q3
> ha
[1] 0.07608884
> hb
[1] 20539.78
> hc
[1] 0.2767364

Answer of Q3
a. 0.0761
b. $20,539.78
c. 0.2767

You might also like