# Statistical Computing Assignment Paper

Statistical Computing

#Problem A. Random number generation and power.

**Definition:** The **power** of a statistical test is the probability the test correctly rejects the null hypothesis when it is indeed false.

# Statistical Computing Assignment Paper

1. Let’s explore the rnorm function. The rnorm() function in R randomly generates data from a normal distribution with a specified mean and a specified standard deviation. Recall we saw the exact equation of the probability distribution function in the notes. The r in rnorm stands for “random.” The data will be randomly drawn based on the probabilities dictated by the probability distribution function.

a. Use the set.seed() function with a seed number of your choosing. Then complete the following: Use rnorm(500) and draw a histogram using ggplot2 tools of the resulting data values. Enter your code in the space provided below so that when you **knit** this document it will show the code and the histogram.

“{r problem1a}

“

b. Use rnorm(500) again and draw a histogram using base tools of the resulting data values. Note: You do not need to use the set.seed() function again. Enter the code in the space provided below.

“{r problem1b}

#Enter your code here.

“

c. Write a few sentences to describe your histograms in parts a) and b). Also, explain What you think the 500 in the code represents. Type our answers below in plain text:

TYPE YOUR ANSWER HERE!

d. Based on a) and b), what do you think the default mean is for the rnorm function? How did the graphs inform your answer? Type your answers below.

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

e. Do you know what the default standard deviation is? How did you determine this?

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

f. Use rnorm(500,100,5) and draw a histogram (base or ggplot2) of the resulting data values. Report your code in the space provided below.

“{r problem1f}

#Enter your code here.

“

g. Use rnorm(500,100,5) again and draw a histogram (base or ggplot2) of the resulting data values. Report your code in the space provided below.

“{r problem1g}

#Enter your code here.

## Statistical Computing Assignment Paper

h. Based on f) and g), what does the second argument (the 100) of the rnorm function do? How did the graphs provide evidence of this for you?

TYPE YOUR ANSWERS HERE IN PLAIN TEXT:

i. What does the third argument (the 5) of the rnorm function do?

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

j. Generate 1000 observations from the F distribution with 5 numerator degrees of freedom and 10 denominator degrees of freedom. Draw a histogram (base or ggplot2) of the data values.

“{r problem1j}

#Enter your code here.

“

k. Write a few sentences to describe the histogram you generated in part j.

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

*Now that you have an understanding of how the rnorm function works, complete the following problems. These items go together to investigate the statistical concept of power.*

2. Create two scalars named rows and samplesize with the values of 10 and 3, respectively. (We will later change these values to 1000 and 30, but while you are working on getting all of your code to run, these smaller values will allow you to print objects and view them to investigate what is going on).

“{r problem2}

#Enter your code here.

“

3. Use the set.seed(1000) function so that we all are randomly generating from the same starting point.

“{r problem3}

#Enter your code here.

“

4. Use the rnorm() function in R in order to randomly generate data from a normal distribution with a mean of 100 and a standard deviation of 5. You should generate enough values to fill in a matrix with the number of rows and the number of columns given by the objects rows and samplesize that you created in #2. You should not retype their values. Instead, reference the objects so that later you can make the change once in the code to explore other rows and sample size options.

“{r problem4}

#Enter your code here.

“

5. Create a matrix of the data values you randomly generated in #4 that has the number of rows given by the scalar you created in #2. Also include code to print the matrix you created.

“{r problem5}

#Enter your code here.

“

6. Calculate the mean of each row of your matrix and store this information in an object called mymeans. Print the output. Answer the question that follows.

“{r problem6}

#Enter your code here.

“

What do you notice about the sample means from your samples and the mean of the normal distribution from which they were drawn?

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

7. Calculate the standard deviation of each row of your matrix and store this information in an object called mysd. Print the output. Answer the question that follows.

“{r problem7}

#Enter your code here.

“

What do you notice about the sample standard deviations from your samples and the standard deviation of the normal distribution from which they were drawn?

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

8. Suppose you planned to test the hypotheses of $H_0: \mu = 107$ vs. $Ha: \mu \neq 107$ in order to determine if the mean of the population from which your data is drawn is different from 107.

a. Question: What is the true mean of the population from which this data is drawn? Type your answer below in plain text.

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

b. Question: Therefore, what do you expect your p-value would look like (small or large)? Type your answer below in plain text.

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

c. Question: Therefore, what is the correct outcome of this test (reject the null or do not reject the null)? Type your answer below in plain text.

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

d. For this test, you would calculate the test statistic as $$t=\frac{\bar{x}-107}{s/\sqrt{n}}$$

Using the objects you created in #6 and #7 and knowing that you created an object in #2 called samplesize, which indicates the size of your sample, calculate this test statistic for every row of your data using R. You do not need the apply function, this is just a calculation involving vectors! Save your vector of test statistics in an object called test.stat. Be very careful with parentheses!! I would calculate the numerator and denominator separately and then divide if I were you! Your code should ultimately print the object test.stat.

“{r problem8d}

#Enter your code here.

“

e. Report the data values (should be 3 values) from the first row of your matrix of data values by using R code to print them. Report the mean and standard deviation of three data values by using R code to calculate these values. Use R as a calculator to calculate the test statistic for these three data values only. Then print the first element of the object test.stat to verify that it was calculated correctly. Be ware of order of operations – PEMDAS!

“{r problem8e}

#Enter your code here.

“

9. We can use the following code to calculate the two-sided p-value:

pvals <- 2*pt(abs(test.stat),lower.tail=_____________,df=________)

Note that the abs() function in R calculates absolute values. I did this because I wanted to only work with the positive version of the test statistics. Since the t-distribution is symmetric, I can use mirror images to calculate p-values more efficiently. Additionally, I can multiple by 2 in order to find the two-sided p-value. Complete the two blanks in the code and run it below. Your outcome should be a vector with one p-value for each row of the data. Print your vector pvals also.

“{r problem9}

#Enter your code here.

“

10. Find the proportion of times the p-values were less than 0.05. Note that you should use a logical comparison to get TRUE/FALSE values for each p-value based on if it is less than 0.05. Then fill in the blanks in the two interpretations below.

“{r problem10}

#Enter your code here.

“

We can interpret the proportion or percentage from your calculated from the previous problem as follows:

Interpretation 1: ___% of the time we correctly rejected the null hypothesis that $H_0: \mu = 107$ when the true population mean is $\mu = 100$ based on samples of size 3.

OR

Interpretation 2: The probability of correctly rejecting the null hypothesis of $H_0: \mu = 107$ when the true population mean is $\mu = 100$ is about ___ based on samples of size 3.

###The remaining problems ask you to re-run your code from #2-10 making changes each time. Copy and paste your code and re-run it to answer the following questions. Do not edit your original code (so that I can grade questions #2-10). Instead, copy and paste all of the individual lines of code from #2-#10 and make the necessary changes. HOWEVER, REMOVE ANY PRINTING OF OBJECTS. I DON’T WANT TO SEE ANYTHING THAT IS 1000 LINES LONG!

11. Our answer in #10 was based on seeing the process repeated a mere 10 times. That’s not enough to see the long-term patterns! Copy your code from #2-10 and paste it below. **Remove any lines of code that would print out objects.** For this problem, I want you to change the number of rows to 1000 so that we can look at the long-term proportion of times the null hypothesis is correctly rejected. Your code should ultimately print out the proportion of times you obtained a p-value of less than 0.05 and therefore rejected the null hypothesis. Also, write a sentence to summarize the proportion you find in context as indicated in the space after your R code.

“{r problem11}

#Enter your code here.

### Statistical Computing Assignment Paper

Type your sentence in plain text here:

12. Our answer in #10 was based on seeing the process repeated a mere 10 times but it was also based on samples of size 3. That’s not very interesting! Copy your code from #11. For this problem, I want you to change the number of rows to 1000 and to change the samplesize to 30 so that we can look at the long-term proportion of times the null hypothesis is correctly rejected for a larger sample size. Your code should ultimately print out the proportion or times you obtained a p-value of less than 0.05 and therefore rejected the null hypothesis. Type your code below. Also, write a sentence to summarize the proportion you find in context as indicated in the space after your R code and answer the questions that follow by typing in plain text.

“{r problem12}

#Enter your code here.

“

Type your sentence in plain text here:

Is this what you would expect? (YES/NO)

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

Explain. Type your answer as plain text here:

TYPE YOUR ANSWER HERE IN PLAIN TEXT:

We can write this or a similar paper for you! Simply fill the order form!

Unlike most other websites we deliver what we promise;

• Our Support Staff are online 24/7
• Our Writers are available 24/7
• Most Urgent order is delivered with 6 Hrs
• 100% Original Assignment Plagiarism report can be sent to you upon request.

GET 15 % DISCOUNT TODAY use the discount code PAPER15 at the order form.

 Type of paper Academic level Subject area Essay Term Paper Research Paper Coursework Book Report Book Review Movie Review Dissertation Thesis Thesis Proposal Research Proposal Dissertation Chapter - Abstract Dissertation Chapter - Introduction Chapter Dissertation Chapter - Literature Review Dissertation Chapter - Methodology Dissertation Chapter - Results Dissertation Chapter - Discussion Dissertation Services - Editing Dissertation Services - Proofreading Formatting Admission Services - Admission Essay Admission Services - Scholarship Essay Admission Services - Personal Statement Admission Services - Editing Editing Proofreading Case Study Lab Report Speech Presentation Math Problem Article Article Critique Annotated Bibliography Reaction Paper PowerPoint Presentation Statistics Project Multiple Choice Questions (None-Time-Framed) Other (Not listed) High School Undergraduate Master Ph. D. Art   Architecture   Dance   Design Analysis   Drama   Movies   Music   Paintings   Theatre Biology Business Chemistry Communications and Media   Advertising   Communication Strategies   Journalism   Public Relations Creative writing Economics   Accounting   Case Study   Company Analysis   E-Commerce   Finance   Investment   Logistics   Trade Education   Application Essay   Education Theories   Pedagogy   Teacher's Career Engineering English Ethics History   African-American Studies   American History   Asian Studies   Canadian Studies   East European Studies   Holocaust   Latin-American Studies   Native-American Studies   West European Studies Law   Criminology   Legal Issues Linguistics Literature   American Literature   Antique Literature   Asian Literature   English Literature   Shakespeare Studies Management Marketing Mathematics Medicine and Health   Alternative Medicine   Healthcare   Nursing   Nutrition   Pharmacology   Sport Nature   Agricultural Studies   Anthropology   Astronomy   Environmental Issues   Geography   Geology Philosophy Physics Political Science Psychology Religion and Theology Sociology Technology   Aeronautics   Aviation   Computer Science   Internet   IT Management   Web Design Tourism Number of pages Paper urgency Cost per page: 1 pages/275 words 2 pages/550 words 3 pages/825 words 4 pages/1100 words 5 pages/1375 words 6 pages/1650 words 7 pages/1925 words 8 pages/2200 words 9 pages/2475 words 10 pages/2750 words 11 pages/3025 words 12 pages/3300 words 13 pages/3575 words 14 pages/3850 words 15 pages/4125 words 16 pages/4400 words 17 pages/4675 words 18 pages/4950 words 19 pages/5225 words 20 pages/5500 words 21 pages/5775 words 22 pages/6050 words 23 pages/6325 words 24 pages/6600 words 25 pages/6875 words 26 pages/7150 words 27 pages/7425 words 28 pages/7700 words 29 pages/7975 words 30 pages/8250 words 31 pages/8525 words 32 pages/8800 words 33 pages/9075 words 34 pages/9350 words 35 pages/9625 words 36 pages/9900 words 37 pages/10175 words 38 pages/10450 words 39 pages/10725 words 40 pages/11000 words 41 pages/11275 words 42 pages/11550 words 43 pages/11825 words 44 pages/12100 words 45 pages/12375 words 46 pages/12650 words 47 pages/12925 words 48 pages/13200 words 49 pages/13475 words 50 pages/13750 words 51 pages/14025 words 52 pages/14300 words 53 pages/14575 words 54 pages/14850 words 55 pages/15125 words 56 pages/15400 words 57 pages/15675 words 58 pages/15950 words 59 pages/16225 words 60 pages/16500 words 61 pages/16775 words 62 pages/17050 words 63 pages/17325 words 64 pages/17600 words 65 pages/17875 words 66 pages/18150 words 67 pages/18425 words 68 pages/18700 words 69 pages/18975 words 70 pages/19250 words 71 pages/19525 words 72 pages/19800 words 73 pages/20075 words 74 pages/20350 words 75 pages/20625 words 76 pages/20900 words 77 pages/21175 words 78 pages/21450 words 79 pages/21725 words 80 pages/22000 words 81 pages/22275 words 82 pages/22550 words 83 pages/22825 words 84 pages/23100 words 85 pages/23375 words 86 pages/23650 words 87 pages/23925 words 88 pages/24200 words 89 pages/24475 words 90 pages/24750 words 91 pages/25025 words 92 pages/25300 words 93 pages/25575 words 94 pages/25850 words 95 pages/26125 words 96 pages/26400 words 97 pages/26675 words 98 pages/26950 words 99 pages/27225 words 100 pages/27500 words 101 pages/27775 words 102 pages/28050 words 103 pages/28325 words 104 pages/28600 words 105 pages/28875 words 106 pages/29150 words 107 pages/29425 words 108 pages/29700 words 109 pages/29975 words 110 pages/30250 words 111 pages/30525 words 112 pages/30800 words 113 pages/31075 words 114 pages/31350 words 115 pages/31625 words 116 pages/31900 words 117 pages/32175 words 118 pages/32450 words 119 pages/32725 words 120 pages/33000 words 121 pages/33275 words 122 pages/33550 words 123 pages/33825 words 124 pages/34100 words 125 pages/34375 words 126 pages/34650 words 127 pages/34925 words 128 pages/35200 words 129 pages/35475 words 130 pages/35750 words 131 pages/36025 words 132 pages/36300 words 133 pages/36575 words 134 pages/36850 words 135 pages/37125 words 136 pages/37400 words 137 pages/37675 words 138 pages/37950 words 139 pages/38225 words 140 pages/38500 words 141 pages/38775 words 142 pages/39050 words 143 pages/39325 words 144 pages/39600 words 145 pages/39875 words 146 pages/40150 words 147 pages/40425 words 148 pages/40700 words 149 pages/40975 words 150 pages/41250 words 151 pages/41525 words 152 pages/41800 words 153 pages/42075 words 154 pages/42350 words 155 pages/42625 words 156 pages/42900 words 157 pages/43175 words 158 pages/43450 words 159 pages/43725 words 160 pages/44000 words 161 pages/44275 words 162 pages/44550 words 163 pages/44825 words 164 pages/45100 words 165 pages/45375 words 166 pages/45650 words 167 pages/45925 words 168 pages/46200 words 169 pages/46475 words 170 pages/46750 words 171 pages/47025 words 172 pages/47300 words 173 pages/47575 words 174 pages/47850 words 175 pages/48125 words 176 pages/48400 words 177 pages/48675 words 178 pages/48950 words 179 pages/49225 words 180 pages/49500 words 181 pages/49775 words 182 pages/50050 words 183 pages/50325 words 184 pages/50600 words 185 pages/50875 words 186 pages/51150 words 187 pages/51425 words 188 pages/51700 words 189 pages/51975 words 190 pages/52250 words 191 pages/52525 words 192 pages/52800 words 193 pages/53075 words 194 pages/53350 words 195 pages/53625 words 196 pages/53900 words 197 pages/54175 words 198 pages/54450 words 199 pages/54725 words 200 pages/55000 words 30 days 6 hours 12 hours 24 hours 48 hours 3 days 4 days 5 days 7 days 10 days 20 days USD  Total: