Question: ### Functions you will need for Homework Data

### Functions you will need for Homework Data<- read.csv("nutrient.csv", header=FALSE) names(Data)=c("obs", "calc", "iron", "prot", "vita", "vitc") attach(Data) # makes variables in Data accessible # Note that the Diamond Rings data has a header, # so you would switch to header=TRUE and then you # don't need to add the names separately. # Problem 1 mean(calc) median(calc) quantile(calc,probs = c(0.1,0.2)) summary(calc) boxplot(calc) hist(calc) hist(calc,prob=TRUE) # Problem 2 plot(iron,calc) # x first, y second cor(iron,calc) # Problem 3 # Y = 1 - X X<-rnorm(25,mean=0,sd=1) Y<-1-X plot(X,Y) cor(X,Y) # Problem 4 # Y = normal with mean 10 and variance 2 # prob(Y < 11) pnorm(11,mean=10,sd=sqrt(2)) # prob(Y>12) 1-pnorm(12,mean=10,sd=sqrt(2)) # or pnorm(12,mean=10,sd=sqrt(2),lower.tail=FALSE) # Problem 5 alpha<- 0.01 n<-5 # multiplier for two sided confidence interval tmult2<-qt(1-0.01/2,df=n-1) # you can double check your intervals using t.test # but you should know how to do it "manually" ### Functions you will need for Homework 2 # Remember in your HW to interpret the parameters in terms of the data # Problem 1 # Lets simulate data from a linear model. # We will generate the X from a normal, # the error from a normal, # and then add the two to get Y. set.seed(1000) # makes sure we all generate the same values n = 50 X = rnorm(n, 1, 2) Y = X + rnorm(n,0,1) plot(X,Y) cor(X,Y) lm_fit<-lm(Y~X) abline(lm_fit,lwd=5) # or beta0_hat<-lm_fit$coefficients[1] beta1_hat<-lm_fit$coefficients[2] abline(beta0_hat,beta1_hat,col="red") # Problem 2 # Easier way to scan in data Data = scan() 1 1 16 2 0 9 3 2 17 4 0 12 5 3 22 6 1 13 7 0 8 8 1 15 9 2 19 10 0 11 Data<-matrix(Data,ncol=3,byrow=TRUE) head(Data)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!