Advertisement
TheLegend12

Untitled

Mar 8th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. ##### R Project 4: Normal Distribution
  2. ##### Name:
  3. ##### Version Number:
  4.  
  5.  
  6. #############################
  7. ###### PART 1 ###############
  8. ###### GRAPH ###############
  9. #############################
  10.  
  11. ## DENSITY FUNCTION
  12. ## C1: Create x-values - code
  13. xvalues_part1 <- seq(-3.7,3.7,by = 0.01)
  14.  
  15.  
  16. ## C2: Create y-values - code
  17. yvalues_part1 <- dnorm(xvalues_part1, mean = 0, sd = 1)
  18.  
  19.  
  20. ## C3: Create Plot - code
  21. ## Remember to save your plot and also submit it to Gradescope.
  22. plot(xvalues_part1, yvalues_part1, type = "l", main = "Standard Normal Probability Density Function (PDF)", xlab = "Variable", ylab = "Density", col = "paleturquoise3")
  23.  
  24.  
  25.  
  26. #############################
  27. ###### PART 1 ###############
  28. ###### QUESTIONS ###########
  29. #############################
  30.  
  31. ## Question 4: Largest approximate y value
  32. # Answer: 0.398942
  33. largest_y_value <- dnorm(0, mean = 0, sd = 1)
  34.  
  35.  
  36.  
  37.  
  38.  
  39. ## Question 5: Why stop at the x-values from C1 instead of something like -1 and +1?
  40. # Answer: There are a couple of reasons to stop at the x-values from C1 instead of something like -1 and +1. One of the reasons is that it covers more than 99.7% of the data. Another reason is that you can observe the behavior of the tails.
  41.  
  42.  
  43.  
  44.  
  45.  
  46. ## Question 6: When calculating a probability, how would this be represented on the graph?
  47. # Answer: If I were to calculate a probability based on this distribution, I would represent a probability based on the standard normal distribution on the standard normal probability density function graph.Particularly, I would visualize the area under the curve within a specific range of x-values.
  48.  
  49.  
  50.  
  51.  
  52.  
  53. ## Question 7: Standard Normal Questions
  54. ## a) What is the mean and variance of the standard normal distribution?
  55. ## Mean = 0
  56. ## Variance = 1
  57.  
  58.  
  59. ## b) What random variable abbreviation do we usually use to represent the standard normal distribution?
  60. ## Answer: Z
  61.  
  62.  
  63. ## c) Based on graph in Part 1, what do the values on the horizontal axis represent?
  64. ## Answer: Based on graph in Part 1, the values on the horizontal axis represent z-scores.
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. #############################
  72. ###### PART 2 ###############
  73. ###### GRAPH ###############
  74. #############################
  75.  
  76. ## CUMULATIVE DISTRIBUTION FUNCTION
  77. ## X ~ N(mean = ????; variance = ????) (see PDF for mean and variance values)
  78.  
  79.  
  80. ## C8: Create x-values - code
  81. xvalues_part2 <- seq(410, 550, by = 7)
  82.  
  83.  
  84. ## C9: Create y-values - code
  85. yvalues_part2 <- pnorm(xvalues_part2, mean = 480, sd = 23, lower.tail = TRUE)
  86.  
  87.  
  88. ## C10: Create Plot - code
  89. plot(xvalues_part2, yvalues_part2, type = "l", main = "Normal CDF", xlab = "x-values", ylab = "P(X <= x): Cumulative Probability", col = "tomato2")
  90.  
  91.  
  92. ## C11: Cumulative Probabilities - code
  93. cumulative_probabilities <- c(0.17, 0.36, 0.50, 0.64, 0.83)
  94.  
  95.  
  96. ## C12: Find x-values associated with cumulative probabilities - code
  97. quantile_for_k <- qnorm(cumulative_probabilities)
  98.  
  99.  
  100. ## C13: Overlay points on plot - code
  101. points(quantile_for_k, cumulative_probabilities, pch = 24, bg = "lavenderblush3", col = "lavenderblush3")
  102.  
  103.  
  104. ## C14: Add text at each point - code
  105. ## Remember to save your plot and also submit it to Gradescope. <- this is the only plot from Part 2 you need to submit.
  106. text(quantile_for_k, cumulative_probabilities, labels = paste("(", round(quantile_for_k,2), ", ", cumulative_probabilities,")", sep = ""), pos = 4)
  107.  
  108.  
  109.  
  110.  
  111.  
  112. #############################
  113. ###### PART 2 ###############
  114. ###### QUESTIONS ###########
  115. #############################
  116.  
  117. ## Question 15: What do the y-values approach as x goes to +/- infinity?
  118. # As x goes towards -infinity: 0
  119.  
  120.  
  121. # As x goes towards +infinity: 1
  122.  
  123.  
  124.  
  125.  
  126.  
  127. ## Question 16: Pick one of the points on your graph from Part 2. Write a probability statement involving the $x$- and $y$- coordinate values that describes how they relate to each other. Do not use the value corresponding to y = 0.5.
  128.  
  129. # Point you will use: (410,0.001169302)
  130. pnorm(410, mean = 480, sd = 23, lower.tail = TRUE)
  131. # Probability Statement: y = P(X <= 410)
  132.  
  133.  
  134.  
  135.  
  136.  
  137. ## Question 17: Create and solve your own probability problem.
  138. ## Must be of the form where you solve for a particular value, given the probability.
  139. ## Do not use any of the points from Q16.
  140. ## Do not use the mean value.
  141. ## Include your code and your final answer.
  142. ## Do NOT use a table or your calculator.
  143.  
  144. # Question: P(X <= a) = 0.25. Solve for a.
  145.  
  146.  
  147. # Code:
  148.  
  149.  
  150. # Answer:
  151.  
  152.  
  153.  
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement