Question: Do the simulation from HW 2 in SAS: In Stat 302, you have 8 homeworks, each worth 50 points. Well model each homework score with
Do the simulation from HW 2 in SAS:
In Stat 302, you have 8 homeworks, each worth 50 points. Well model each homework score with a truncated discretized Normal(40, 10) distribution; that is, to get a score, generate a Normal random variable with mean 40 and standard deviation 10, then round it to the nearest integer (yes, there is a function called round in R). Then if the score is below 0, make it 0; and if its above 50, make it 50.
Your total score is the sum of 8 homework scores, rescaled to the range 0 to 100.
Your adjusted score is the sum of your 7 highest scores (that is, drop the lowest score). Its also rescaled to the range 0 to 100.
Write a function to sample (that is, generate) a vector with 8 homework scores.
Write a function to calculate your total score from the vector of 8 homework scores (this is easy).
Write a function to calculate the adjusted score from the vector of 8 homework scores. This might be a little tricky; think about using the min() or max() functions.
Now sample both the total score and an adjusted score 10000 times. Weve done this in class using a for loop; the replicate() function makes it easier - but youll want to look up how to use it. For both the total score and adjusted score (youll probably want to first do this for the total score, then the adjusted score, separately): Plot a histogram, find the mean, standard deviation, and the summary() statistics. Whats the probability (as estimated from the simulation) that your total score is above 90%? Whats the probability that your adjusted score is above 90%?
Change: instead of summary statistics, in SAS try to generate mean, median, and standard deviation for the two scores. Instead of replicate(), use a do loop (we didnt quite get to it in lecture but its in SAS slides #5)
I will attach the R code for same assignment for your help please change this to SAS
```{r} sampling <- function() { hw0 <- round(rnorm(8, 40, 10)) hw <- pmin(50, pmax(0, hw0)) return (hw) } sampling()
total_score <- function(hw) { sum(hw)*2 } total_score(sampling())
adjusted_score <- function(hw) { (sum(hw)-min(hw))*2 } adjusted_score(sampling())
n <- 10000 TotalScoreSamples <- replicate(n, total_score(sampling())) AdjustedScoreSamples <- replicate(n, adjusted_score(sampling()))
hist(TotalScoreSamples) mean(TotalScoreSamples) sd(TotalScoreSamples) summary(TotalScoreSamples)
hist(AdjustedScoreSamples) mean(AdjustedScoreSamples) sd(AdjustedScoreSamples) summary(AdjustedScoreSamples)
probability_total <- (TotalScoreSamples) > (0.9*(800)) sum(probability_total)/length(probability_total) probability_adj <- (AdjustedScoreSamples) > (0.9*(700)) sum(probability_adj)/length(probability_adj) ```
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
