R Markdown

Problem 1

w=c(153.16, 146.45, 144.20, 145.60, 154.07, 151.95) #w now stores this list of weights
mean_w = mean(w) #assigns mean weight from w to mean_w
med_w = median(w) #assigns median weight from w to med_w
sd_w = sd(w) #assigns standard deviation of weight from w to sd_w
hist(w,
     main = "Histogram of Weight Distribution", #creating title
     xlab = "Weights", #labling x-axis
     ylab = "Frequency") #labling y-axis

Problem 2

x = rnorm(100, mean = 1, sd = 2) #given N(1,4), sd^2=4, so sd=2
hist(x,
     main = "Histogram of N(1,4) Distribution",
     freq = FALSE)

# overlay density line
xseq = seq(from=min(x), to=max(x), length.out=100) #generates even-spaced 100 numbers from min(x) to max(x)
density_values = dnorm(xseq, mean = 1, sd = 2) # normal density values evaluated at xseq
lines(xseq,density_values) # add the density line to the previous histogram

e = rnorm(100, mean = 0, sd = 1) #generating 100 samples given N(0,1)
y=3*x +e
scatter.smooth(x, y)

Problem 6 (Part 2)

p1 = pnorm(1) - pnorm(-1) #takes the cdfs of, by default, N(mean=0, sd=1) for the proportion less than -1 from the proportion less than 1
p2 = pnorm(sqrt(2))-pnorm(-sqrt(2)) #takes the proportion between the the sqrt of 2 and negative sqrt of 2 for a Normal distribution


T1 = rnorm(10000, mean = 50, sd = 5) #samples 10,000 from a Normal rv with mean=0, sd=1
pT1 = mean(T1>=45 & T1<=55) #gives the probability from the sample to estimate P(45<=T_1<=55)

T2 = rnorm(10000, mean = 50, sd = 5) #samples 10,000 from a Normal rv with mean=0, sd=1
T3 = ((T1+T2)/2) #takes the average of T1 and T2 samples
pT3 = mean(T3>=45 & T3<=55) #gives the probability from the samples to estimate P(45<=average of T1 and T2<=55)