The objective of this assignment is to introduce you to R and R markdown and to complete some basic data simulation exercises.
Please include all code needed to perform the tasks. This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
To submit this homework you will create the document in Rstudio, using the knitr package (button included in Rstudio) and then submit the document to your Rpubs account. Once uploaded you will submit the link to that document on Canvas. Please make sure that this link is hyperlinked and that I can see the visualization and the code required to create it.
# place the code to simulate the data here
set.seed(0)
samples<-rnorm(30, mean=c(0,1,-1), sd=c(1,10,100))
print(samples)
## [1] 1.26295428 -2.26233361 131.97992629 1.27242932 5.14641434
## [6] -154.99500419 -0.92856703 -1.94720447 -1.57671727 2.40465339
## [11] 8.63593461 -80.90092490 -1.14765701 -1.89461574 -30.92151179
## [16] -0.41151083 3.52223448 -90.19211273 0.43568330 -11.37538422
## [21] -23.42678853 0.37739565 2.33336361 79.41895097 -0.05710677
## [26] 6.03607972 107.57693621 -0.69095384 -11.84599354 3.67261722
# place the code to simulate the data here
set.seed(0)
x<-rnorm(20, 0, 1)
y<-rnorm(20, 0, 1)
plot(y~x)
# place the code to simulate the data here
set.seed(0)
x1<-runif(100, 1, 10)
x2<-runif(100, 100, 200)
y<-rnorm(100, 0, 1)
z<-lm(y~x1+x2)
print(z)
##
## Call:
## lm(formula = y ~ x1 + x2)
##
## Coefficients:
## (Intercept) x1 x2
## -0.258487 -0.027168 0.002424
plot(z)
# place the code to simulate the data here
rep(LETTERS[1:3], each=2, times=2)
## [1] "A" "A" "B" "B" "C" "C" "A" "A" "B" "B" "C" "C"
# place the code to simulate the data here
df<-data.frame(group=rep(LETTERS[1:3]), factor=rep(LETTERS[24:25], length.out=27), response1=rnorm(n=27, mean=0, sd=1), response2=rnorm(n=27, mean=2, sd=10))
df
## group factor response1 response2
## 1 A X -1.04571765 -8.7501019
## 2 B Y -0.89621126 6.0654273
## 3 C X 1.26938716 24.2926220
## 4 A Y 0.59384095 -13.1449701
## 5 B X 0.77563432 1.3829258
## 6 C Y 1.55737038 0.5272921
## 7 A X -0.36540180 17.4159307
## 8 B Y 0.81655645 -7.8185567
## 9 C X -0.06063478 6.9657817
## 10 A Y -0.50137832 18.9694788
## 11 B X 0.92606273 -0.6073631
## 12 C Y 0.03693769 -5.0592859
## 13 A X -1.06620017 0.3882149
## 14 B Y -0.23845635 7.0132183
## 15 C X 1.49522344 -8.1353967
## 16 A Y 1.17215855 18.1475224
## 17 B X -1.45770721 2.0564198
## 18 C Y 0.09505623 -27.0489906
## 19 A X 0.84766496 -9.0716482
## 20 B Y -1.62436453 17.4756693
## 21 C X 1.40856336 -7.7683035
## 22 A Y -0.54176036 0.9849655
## 23 B X 0.27866472 2.4265025
## 24 C Y -0.19397274 -13.9671801
## 25 A X 1.57615818 6.9096737
## 26 B Y -1.47554764 6.2160337
## 27 C X -0.14460821 20.7390390