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

Enter the following chunk to arrange the random draws into separate arrays each

ID: 3075054 • Letter: E

Question

Enter the following chunk to arrange the random draws into separate arrays each with 1000 rows, and either 4, 9, or 36 columns, and then compute the row means of these arrays, in order to build three vectors each containing 1000 realizations ("muhats") from the sampling distributions of the mean, for samples of sizes 4, 9, and 36 respectively:

1. Characterize XX by naming the distribution of this random variable and =E[X]=E[X] and 2=Var[X]2=Var[X] . Also compute =Var[X]=Var[X].

2. Find the sample mean and variance using the 49000 realizations of XX in xs and compare that to what you found in the previous question.

3. Using your answer in problem 1 and what we are learning about the expectation and variance of samping distributions to give the expectation and variance of each ^4^4muhats4, ^9^9 muhats9, and ^36^36 muhats36. Also compute ^4^4, ^9^9 and ^36^36, the standard deviation of each element of the respective vectors, for use in problem 4.

4. Compute the sample mean and sample standard deviation of the realizations in muhats4, muhats9, and muhats36 by applying the mean and sd functions in RR to these objects. Compare these to their analogous formal properties of the sampling distributions of the elements in the previous question. What happens to the variance of the sampling distributions for the various statistics ^^ when we base them off of increasing amounts of the original data (4, 9, and 36 realizations of XX, respectively).

5. Now compute the sample mean and standard deviation of (X0.5)2(X0.5)2 by applying the mean and sd function in RR to (xs-0.5)^2. How does the sample mean compare to (E[X]0.5)2(E[X]0.5)2? What happens to the standard deviation relative to Var[X]Var[X]?This simple Monte Carlo experiment demonstrates that in general, E[g(X)]___E[g(X)]___ and ___Var[X]___Var[X] (fill in the blanks).

Explanation / Answer

import java.util.*;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class HelloWorld{

public static void main(String[] args) {
int rows,cols,sum=0,rowsum=0,colsum=0;
double avg=0.0;
Scanner in=new Scanner(System.in);
System.out.println("Enter the number of rows");
rows=in.nextInt();
System.out.println("Enter the number of columns");
cols=in.nextInt();
int values[][] = new int[rows][cols];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
values[i][j] = ((int) (Math.random() * 10));
System.out.print(values[i][j]);
}
// add a new line
System.out.println();
}
System.out.println("Done");
  
try {
           File file = new File("input.txt");
           FileReader fileReader = new FileReader(file);
           BufferedReader bufferedReader = new BufferedReader(fileReader);
           StringBuffer stringBuffer = new StringBuffer();
           String line;
           while ((line = bufferedReader.readLine()) != null) {
               stringBuffer.append(line);
               stringBuffer.append(" ");
           }
           fileReader.close();
           System.out.println("Contents of file:");
           System.out.println(stringBuffer.toString());
       } catch (IOException e) {
           e.printStackTrace();
       }
       try { File file = new File("input.txt");
FileReader fr = new FileReader(file);
char temparr[] = new char[(int) file.length()];
fr.read(temparr,0,(int) file.length());
String [] tempstring = (new String(temparr)).split(" ");
String array2d[][] = new String [tempstring.length][];
for(int i=0 ; i<tempstring.length; i++)
{
array2d[i]=tempstring[i].split(" ");   
}
       }
       catch (IOException e) {
           e.printStackTrace();
       }
      
       for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
  
sum+=values[i][j];
}
}
System.out.println("Sum of 2D array"+sum);
avg=(sum/(rows*cols));
System.out.println("Avg of 2D array"+avg);
for(int i = 0; i<cols;i++) {
for( int j = 0; j<rows; j++) {
rowsum = rowsum + values[i][j];
}
System.out.println("Sum of row " + rowsum);
rowsum=0;
}
int col = 0;
for(int i=0; i<rows;i++) {
for(int j=0; j<cols; j++) {
colsum = colsum + values[i][j];
}
System.out.println("Sum of column " +" is " + colsum);
colsum=0;
}
}
}