Question

Preview of Homework 1 R.1 The probability distribution for diff R.2 The probability distribution for max R.3 Expected value of diff R.4 Expected value of max R.6 Expected diff squared R.7 Expected max squared R.9 Variance of diff R.10 Variance of max Histogram for max Histogram for diff4. Now we return to the red and green dice from Homework 1. Use the lines below to simulate the random variables from Doughertys Chapter 1 problems, and then use R to estimate the answers to each of the problems below. ## Generating the Random Variables for Pages 13 and 14 red - sample (c(1:6),repl-T, size-10000) green = sample(c(1:6),repl-T,size-10000) sum = red-green max - ifelse (red > green, red, green) diff abs(red-green) table (sum) ## sum ## 2 3 4 5 6 7 8 9 10 11 12 ## 281 605 806 1075 1333 1679 1401 1123 841 576 280 mean (sum) ## [1] 7.0148 mean (sum 2) ## [1] 55.1342 var (sum) ## [1] 5.927374 sd (sum) ## [1] 2.43462 sum( (sum-mean (sum)) 2/9999 ## [1] 5.927374 mean (sum 2)-mean (sum)2 ## [1] 5.926781 Why doesnt the last expression equal the other variances? (Because mean divides by n and not n - 1 hist (sum)Histogram of sum 4 10 12 sum

Need help with the codings in R Markdown (in R Studio)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sol: Since sample mean and sample variance is unbiased estimator of population mean and population variance respectively.

E(ar{x})=mu    and

E(s^2)=sigma ^2

Where,

ar{x} is a sample mean and mu is a population mean.

s^2=rac{1}{n-1}sum (x_{i}-ar{x})^2 is sample variance.

(ri -T) is population variance.

Therefore, R-code result gives approximately same value of sample variance (dividing by n-1) and population variance (dividing by n)

> red=sample(c(1:6),repl=T,size=10000)
> green=sample(c(1:6),repl=T,size=10000)
> sum=red+green
> max=ifelse(red>green, red, green)
> diff=abs(red-green)
> table(sum)
sum
   2    3    4    5    6    7    8    9   10   11   12
270 555 850 1132 1380 1649 1372 1084 848 591 269
> mean(sum)
[1] 7.0029
> mean(sum^2)
[1] 54.9115
> var(sum)
[1] 5.871479
> sd(sum)
[1] 2.423113
> sum((sum-mean(sum))^2)/9999 # This case provides sample variance.
[1] 5.871479
> mean(sum^2)-mean(sum)^2    # This case provides population variance.
[1] 5.870892
> hist(sum)

Add a comment
Know the answer?
Add Answer to:
Need help with the codings in R Markdown (in R Studio) Preview of Homework 1 R.1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HELP WITH THE FOLLOWING R CODE! I NEED HELP WITH PART C AND D, provided...

    PLEASE HELP WITH THE FOLLOWING R CODE! I NEED HELP WITH PART C AND D, provided is part a and b!!!! a) chiNum <- c() for (i in 1:1000) { g1 <- rnorm(20,10,4) g2 <- rnorm(20,10,4) g3 <- rnorm(20,10,4) g4 <- rnorm(20,10,4) g5 <- rnorm(20,10,4) g6 <- rnorm(20,10,4) mse <- (var(g1)+var(g2)+var(g3)+var(g4)+var(g5)+var(g6))/6 M <- (mean(g1)+mean(g2)+mean(g3)+mean(g4)+mean(g5)+mean(g6))/6 msb <- ((((mean(g1)-M)^2)+((mean(g2)-M)^2)+((mean(g3)-M)^2)+((mean(g4)-M)^2)+((mean(g5)-M)^2)+((mean(g6)-M)^2))/5)*20 chiNum[i] <- msb/mse } # plot a histogram of F statistics h <- hist(chiNum,plot=FALSE) ylim <- (range(0, 0.8)) x <- seq(0,6,0.01) hist(chiNum,freq=FALSE, ylim=ylim)...

  • Need help for the coding using the R Markdown in R Studio for question2 and question2....

    Need help for the coding using the R Markdown in R Studio for question2 and question2. Please provide a detailed solution with an original R code, outputs and a clear statement of the final answer. First, verify by typing out the terms in the appropriate formulas for the t-statistic and the confidence limits that you and R agree about how these should be calculated. For instance, your R code should be structured the way the Excel commands for confidence limits...

  • R studio #Exercise : Calculate the following probabilities : #1. Probability that a normal random variable...

    R studio #Exercise : Calculate the following probabilities : #1. Probability that a normal random variable with mean 22 and variance 25 #(i)lies between 16.2 and 27.5 #(ii) is greater than 29 #(iii) is less than 17 #(iv)is less than 15 or greater than 25 #2.Probability that in 60 tosses of a fair coin the head comes up #(i) 20,25 or 30 times #(ii) less than 20 times #(iii) between 20 and 30 times #3.A random variable X has Poisson...

  • Consider the number of days absent from a random sample of six students during a semester:...

    Consider the number of days absent from a random sample of six students during a semester: A= {2, 3, 2, 4, 2, 5} Compute the arithmetic mean, geometric mean, median, and mode by hand and verify the results using R Arithmetic Mean: X=i=1nXin=2+3+2+4+2+56=3 mean(data2$absent) [1] 3 Geometic Mean: GMx=Πi=1nX11n=2∙3∙2∙4∙2∙516=2.79816 >gmean <- prod(data2$absent)^(1/length(data2$absent)) > gmean [1] 2.798166 Median: X=12n+1th, Xi2,2,2,3,4,5, n=6=126+1th ranked value=3.5, value=2.5 days absent >median(data2$absent) [1] 2.5 Mode: Most frequent value=2 > mode <- names(table(data2$absent)) [table(data2$absent)==max(table(data2$absent))] > mode [1]...

  • For expert using R , I solve it but i need to figure out what I...

    For expert using R , I solve it but i need to figure out what I got is correct or wrong. Thank you # Simple Linear Regression and Polynomial Regression # HW 2 # # Read data from csv file data <- read.csv("C:\data\SweetPotatoFirmness.csv",header=TRUE, sep=",") head(data) str(data) # scatterplot of independent and dependent variables plot(data$pectin,data$firmness,xlab="Pectin, %",ylab="Firmness") par(mfrow = c(2, 2)) # Split the plotting panel into a 2 x 2 grid model <- lm(firmness ~ pectin , data=data) summary(model) anova(model) plot(model)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT