Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do use a computer (i.e. R/R Studio) for this problem, and include any relevant R

ID: 3207060 • Letter: D

Question

Do use a computer (i.e. R/R Studio) for this problem, and include any relevant R code and output used to achieve the solution. Write your own function that computes the second moment of a discrete random variables. The input should be a matrix with two columns, with the possible values of the random variable in the first column, and the corresponding probabilities in the second column. The function should be called your first name initial plus your last name. For example, mine would be called mwang: > mwang = function (X) {...} Use your function from part (a) on X1 = cbind c (2, 4, 6, 8), c (0.1, 0. 2, 0. 4, 0.3) X2 = c bind c (0, 3, 6, 9, 12), c (0.20, 0.10, 0.30, 0.15, 0.25))

Explanation / Answer

R-Script

mwang=function(x)
{
firstmoment=x[,1]*x[,2]
secondrawmoment=(x[,1]^2)*x[,2]
secondcentralmoment=sum(secondrawmoment)-(sum(firstmoment))^2
print("secondcentralmoment is")
secondcentralmoment
}
x1=cbind(c(2,4,6,8),c(0.1,0.2,0.4,0.3))
x2=cbind(c(0,3,6,9,12),c(0.2,0.10,0.30,0.15,0.25))
mwang(x1)
mwang(x2) > mwang=function(x)
+ {
+ firstmoment=x[,1]*x[,2]
+ secondrawmoment=(x[,1]^2)*x[,2]
+ secondcentralmoment=sum(secondrawmoment)-(sum(firstmoment))^2
+ print("secondcentralmoment is")
+ secondcentralmoment
+ }
> x1=cbind(c(2,4,5,8),c(0.1,0.2,0.4,0.3))
> x2=cbind(c(0,3,6,9,12),c(0.2,0.10,0.30,0.15,0.25))
> mwang(x1)
[1] "secondcentralmoment is"
[1] 3.64
> mwang(x2)
[1] "secondcentralmoment is"
[1] 18.2475
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote