Question

In: Statistics and Probability

[Lumley] Write an R function that takes inputs n1, n2, N1, N2, σ12,σ2and computes the variance...

[Lumley] Write an R function that takes inputs n1, n2, N1, N2, σ12,σ2and computes the variance of the population total in a stratified sample. Choose some reasonable values of the population sizes and variances, and graph this function as n1 and n2 change, to find the optimum and to examine how sensitive the variance is the precise values of n1 and n2.

Solutions

Expert Solution

Solution:

For stratified sampling, variance of population total is given as,

Variance of population total=variance=N^2 * sum((Ni / N)^2 *(Ni-ni) / Ni *(s^2 / Ni))

   =

where,

L=number of strata

N=the sum of all stratum sizes

Ni=size of ith stratum

Yi bar =sample mean of ith stratum

ni =number of observations in ith stratum

si =sample standard deviation of ith stratum

We have to create function var_ptotal as,

R code:

var_ptotal=function(n1,n2,N1,N2,s1,s2,y1bar,y2bar) {
y_bar=(N1*y1_bar+N2*y2_bar)/N;
Var_ybar=((N1/N)^2)*((N1-n1)/N1)*(s1^2)/n1+((N2/N)^2)*((N2-n2)/N2)*(s2^2)/n2;
#estimation for total and its variance
tau_hat=N*y_bar;
Varp=(N^2)*Var_ybar;
print(Varp)
}
var()

n1=40:60
n2=30:50
for(i in 1:n1)
{
for(j in 1:n2)
{
v[i,j]=var_ptotal(n1,n2,100,150,23,21,2,3)
plot(v,main="Variance plot",ylab="variance")
}
}
R= output:

[1] 343950.0 330055.0 316980.5 304655.1 293015.5 282005.6 271575.0 261678.9 252276.8 243332.3
[11] 234812.5 226687.7 218930.8 211517.1 204424.3 197631.8 191120.8 184874.0 178875.6 [20] 173111.0 167566.7

from above plot it can be seen that variance decreases as sample size increases.


Related Solutions

Write a function in python that takes in an integer n and computes the left hand...
Write a function in python that takes in an integer n and computes the left hand Riemann sum of the function f(x) = x^2 on the interval [0,1]. Hint: compute the error from the true answer
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval...
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval 0 to 360. function de=equivalent(d) For example, equivalent(540) = 180 equivalent(-30) = 330
In C++, write a function that takes in as inputs two arrays, foo and bar, and...
In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.
In R: write a function that inputs a vector x and a number n and returns...
In R: write a function that inputs a vector x and a number n and returns the first n elements of x. When n is greater than length(x), your function should just return x. We are not allowed to use any control flow statements
Write a function myfn6 which takes as inputs vector u and value a, and output as...
Write a function myfn6 which takes as inputs vector u and value a, and output as vector w with its elements being “True, ” or “False, ”(w = [True, False, False, …, True]). Such that “True, ” means a is in u and “False, ” means a is not in u. Test your code for u = [0, -3, 1, 1, 2, 2, 6, 2] and a = 9, a = 1 and a = 2. Copy your code together...
This is the question Write a function add(vals1, vals2) that takes as inputs two lists of...
This is the question Write a function add(vals1, vals2) that takes as inputs two lists of 0 or more numbers, vals1 and vals2, and that uses recursion to construct and return a new list in which each element is the sum of the corresponding elements of vals1 and vals2. You may assume that the two lists have the same length. For example: >>> add([1, 2, 3], [3, 5, 8]) result: [4, 7, 11] Note that: The first element of the...
Write a LISP function POWER that takes a list containing exactly two numeric atoms and computes...
Write a LISP function POWER that takes a list containing exactly two numeric atoms and computes the first atom raised to the power of the second atom. For example: (POWER ‘(2 4) Returns the value 16
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
Python. Write a function last_occur(s, e) that takes as inputs a sequence (i.e., a string or...
Python. Write a function last_occur(s, e) that takes as inputs a sequence (i.e., a string or list) s and an element e, and that calls itself recursively to find and return the index of the last occurrence of e in s. If s is a string, e will be a single-character string; if s is a list, e can be any value. Don’t forget that the index of the first element in a sequence is 0. Important notes: If e...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT