1) Variance and Standard Deviation of a Discrete
Random Variable
We were given two probability distribution tables and asked to find the
variance and standard distribution of each.
Table #1
X
|
p(x)
|
0
|
0.50
|
1
|
0.20
|
2
|
0.15
|
3
|
0.10
|
Table #2
x
|
P(x)
|
1
|
0.10
|
3
|
0.20
|
5
|
0.60
|
4
|
0.20
|
R Studio Coding
Table #1 is represented by x and Table #2 is
represented by y.
x <- c(0.5, 0.2, 0.15, 010)
y <- c(0.10, 0.2, 0.6, 0.2)
Then simply find the variance and standard deviation
of each vector by using the var and sd
functions.
varianceX <- var(x)
standardX <- sd(x)
varianceY <- var(y)
standardY <- sd(y)
You can print the results:
varianceX
varianceY
standardX
standardY
R reports
that the variance of Table #1 is 23.62729 and Table #2 is 23.62729. The standard
deviation of Table #1 is 4.860791 while Table #2 is 0.2217356.
The R Markdown of this script:
x
<- c(0.5, 0.2, 0.15, 010) y <- c(0.10, 0.2, 0.6,
0.2)
varianceX <- var(x) standardX <- sd(x)
varianceY <- var(y) standardY <- sd(y)
varianceX
[1]
23.62729 varianceY
[1] 0.04916667
standardX
[1]
4.860791 standardY
[1] 0.2217356
2) Binomial Distribution:
To find the Binomial Distribution of P(0) in R, we
use the dbinom function.
dbinom(x = 0, size = 4, prob = 0.2)
R computes the value to be 0.4096.
3) Poisson Distribution:
The first
technique using rpois function. By
using the rpois function, we can
generate a vector of 20 random numbers.
#
rpois(n, lambda) randomNums <- rpois(20, 4)
Plug the
vector into our var function and we can find the variance of all 20 randomly
generated numbers.
variance <- var(randomNums)
##Then tell R to show us the results using randomNums
##Here is the compiled R Markdown of this script:
randomNums <- rpois(20, 4)
variance <- var(randomNums)
randomNums
[1]52244384165314274425
variance
[1] 3.536842*
##Poisson random number
ranx <- rpois(20, lambda = 4)
ranx
##expected value (sample mean)
mean(ranx)
##variance
var(ranx)
> ##Poisson random number
> ranx <- rpois(20, lambda
= 4)
> ranx
[1] 38812556469343524445
> mean(ranx)
[1] 4.55
>
>
##variance > var(ranx)
[1] 4.365789
- Does the sample proportion p have approximately a normal distribution? Explain.
Comments
Post a Comment