Question

In: Statistics and Probability

Develop two functions in R, one that generates s^2 using the formation definition, and one that...

Develop two functions in R, one that generates s^2 using the formation definition, and one that calculates s^2 based on the hand calculation equation. Generate data from a normal distribution. Use your functions to calculate s^2 for your generated data. Try this for various variances so that your data become closer and closer to the mean (less variance). What do you find, comment.

Solutions

Expert Solution

#Here we create two functions forsample variance S^2 is s.2() and and population variance sigma2()

#The R code is

s.2=function (X){
sumx=0
sumsqx=0
n=length(X)
for(i in 1:n){
sumx=sumx+X[i]
sumsqx=sumsqx+(X[i]*X[i])
}
mx=sumx/n
S.2=((sumsqx/n)-mx^2)*(n/(n-1))
print(S.2)
}

sigma2=function (X){
sumx=0
sumsqx=0
n=length(X)
for(i in 1:n){
sumx=sumx+X[i]
sumsqx=sumsqx+(X[i]*X[i])
}
mx=sumx/n
S.2=((sumsqx/n)-mx^2)
print(S.2)
}

#we take mean is 3 and Variance are
var=seq(0.1,1,0.1)
var

 [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

for( sd in sqrt(var)){

X=rnorm(100,3,sd)

cat("Mean is",mean(X),"S^2is",s.2(X),"Sigma^2",sigma2(X),"\n")

}

] 0.0957932 [1] 0.09483527 Mean is 2.992832 S^2is 0.0957932 Sigma^2 0.09483527 [1] 0.2243562 [1] 0.2221126 Mean is 2.996699 S^2is 0.2243562 Sigma^2 0.2221126 [1] 0.2326334 [1] 0.2303071 Mean is 2.992128 S^2is 0.2326334 Sigma^2 0.2303071 [1] 0.4644581 [1] 0.4598135 Mean is 3.018703 S^2is 0.4644581 Sigma^2 0.4598135 [1] 0.5027912 [1] 0.4977633 Mean is 2.926998 S^2is 0.5027912 Sigma^2 0.4977633 [1] 0.547224 [1] 0.5417517 Mean is 2.819986 S^2is 0.547224 Sigma^2 0.5417517 [1] 0.6746021 [1] 0.6678561 Mean is 2.979211 S^2is 0.6746021 Sigma^2 0.6678561 [1] 0.9897457 [1] 0.9798482 Mean is 2.831677 S^2is 0.9897457 Sigma^2 0.9798482 [1] 1.08549 [1] 1.074635 Mean is 2.920762 S^2is 1.08549 Sigma^2 1.074635 [1] 0.9912502 [1] 0.9813377 Mean is 3.04267 S^2is 0.9912502 Sigma^2 0.9813377

#here the mean is closure to 3 and Variance is closure to various value,for generated sample with parameter mean is 1 and Variance is 1 the sample will show mean is approximately 3 and by using function S^2 i.e. s.2 is approximately 1 than sigma2 function

Here s.2 is a sample mean square which is an unbiased estimator of population variance.The difference from S^2 to Population varaince is minimum than Sigma2 which is biased estimator of population varaince

i.e.sample mean square S^2 show low variation from population variance


Related Solutions

Develop two functions in R, one that generates s^2 using the formation definition, and one that...
Develop two functions in R, one that generates s^2 using the formation definition, and one that calculates s^2 based on the hand calculation equation. Generate data from a normal distribution. Use your functions to calculate s^2 for your generated data. Try this for various variances so that your data become closer and closer to the mean (less variance). What do you find, comment.
L = {a r b s | r, s ≥ 0 and s = r 2}....
L = {a r b s | r, s ≥ 0 and s = r 2}. Show that L is not regular using the pumping lemma
Let L = {0 r | r = s 2 , s a positive integer}. Give...
Let L = {0 r | r = s 2 , s a positive integer}. Give the simplest proof you can that L is not regular using the pumping lemma.
Consider the following model of interacting species: R' = R(2 + 3R − S) S' =...
Consider the following model of interacting species: R' = R(2 + 3R − S) S' = S(1 − S + 4R) (a) Find all the equilibrium points, and determine the type of those points which are in the first quadrant (including those on the axes) (b) Plot the phase portrait of the system. (c) If the initial conditions are R(0) = 1 and S(0) = 1, what will be the population size of each species when t → ∞?
Find the laplace transform of the following functions, using the definition of Laplace transforms: f(t)=-2cos4t f(t)=2...
Find the laplace transform of the following functions, using the definition of Laplace transforms: f(t)=-2cos4t f(t)=2 sin^2(t) g(t)=3e^tcos(t)
Why would it be unreasonable to study the enthalpy of formation of Mg0(s) by directly using...
Why would it be unreasonable to study the enthalpy of formation of Mg0(s) by directly using your Styrofoam calorimeter? Why is Hess's law a good way to study this reaction? Give one other example of a reaction that could not be studied using a Styrofoam container. (Hint: What solvents are used dissolve polystyrene?)
Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
​Micro-Pub, Inc., is considering the purchase of one of two microfilm​ cameras, R and S. Both...
​Micro-Pub, Inc., is considering the purchase of one of two microfilm​ cameras, R and S. Both should provide benefits over a​ 10-year period, and each requires an initial investment of ​$3,000. Management has constructed the following table of estimates of rates of return and probabilities for​ pessimistic, most​ likely, and optimistic​ results Camera R Camera S Amount Probability Amount Probability Initial investment ​$3,000 1.00 ​$3,000 1.00 Annual rate of return Pessimistic 21​% 0.21 16​% 0.23 Most likely 27​% 0.46 29​%...
Micro-Pub, Inc., is considering the purchase of one of two microfilm​ cameras, R and S. Both...
Micro-Pub, Inc., is considering the purchase of one of two microfilm​ cameras, R and S. Both should provide benefits over a​ 10-year period, and each requires an initial investment of ​$3,000. Management has constructed the following table of estimates of rates of return and probabilities for​ pessimistic, most​ likely, and optimistic​ results Camera R Camera S Amount Probability Amount Probability Initial investment ​$3,000 1.00 ​$3,000 1.00 Annual rate of return Pessimistic 21​% 0.21 16​% 0.23 Most likely 27​% 0.46 29​%...
develop a mathematical model using fortran 77 on pulse tube cryocooler using r 407 as a...
develop a mathematical model using fortran 77 on pulse tube cryocooler using r 407 as a refrigerant please write the code in fortran 77 language only and verify the code generated with the help of photon 95628 from both the virgin the answer is accurate validate the reason with the available theoretical answers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT