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

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.
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...
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
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...
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...
Write an R function that conducts a normality test as follows: it takes as input a...
Write an R function that conducts a normality test as follows: it takes as input a data set, calculates a bootstrap confidence interval for the skewness, calculates a bootstrap confidence interval for the kurtosis, then sees if 0 is in the skewness interval and 3 is in the kurtosis interval. If so, your routine prints that the data is normally distributed, otherwise your routine should print that the data is not normally distributed. Test your routine on random data from...
In R studio Write a function that takes as an input a positive integer and uses...
In R studio Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Use the lapply function, do not use any of the loop commands in your code.
Write a function add(vals1, vals2) that takes as inputs two lists of 0 or more numbers,...
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 result is the sum...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x_start and ending at x_end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equallength sub-intervals in which the interval from x_start to x_end should be divided. Here,...
Say that two users use n1, n2 in the RSA and gcd(n1, n2) =/= 1. How...
Say that two users use n1, n2 in the RSA and gcd(n1, n2) =/= 1. How can we break their system?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT