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(1)
rnorm(30, mean = c(0,2,10), sd = c(1,2,4))
## [1] -0.62645381 2.36728665 6.65748555 1.59528080 2.65901554
## [6] 6.71812646 0.48742905 3.47664941 12.30312541 -0.30538839
## [11] 5.02356234 11.55937295 -0.62124058 -2.42939977 14.49972367
## [16] -0.04493361 1.96761947 13.77534484 0.82122120 3.18780264
## [21] 13.67590949 0.78213630 2.14912997 2.04259322 0.61982575
## [26] 1.88774252 9.37681797 -1.47075238 1.04369989 11.67176624
# place the code to simulate the data here
x = rnorm(20, 0, 1)
y = rnorm(20, 0, 1)
plot(y~x)
# place the code to simulate the data here
set.seed(2)
x1 = runif(50, 1, 5)
x2 = runif(50, 10, 25)
y = rnorm(50, 0, 1)
yfit = lm(y~x1 + x2)
plot(yfit)
# 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
group = rep(letters[1:3],length.out=30)
factor= rep(letters[4:5], length.out=30)
response = replicate(n=2, expr = rnorm(30, mean = 0, sd = 1))
data.frame(group, factor, response)
## group factor X1 X2
## 1 a d 1.0744594 0.68980417
## 2 b e 0.2605978 0.33096318
## 3 c d -0.3142720 0.87106771
## 4 a e -0.7496301 -2.01624558
## 5 b d -0.8621983 1.21257910
## 6 c e 2.0480403 1.20049470
## 7 a d 0.9399201 1.03206833
## 8 b e 2.0086871 0.78641026
## 9 c d -0.4213736 2.11007351
## 10 a e -0.3508344 -1.45380985
## 11 b d -1.0273806 -0.58310385
## 12 c e -0.2505191 0.40972398
## 13 a d 0.4718595 -0.80698164
## 14 b e 1.3589398 0.08555044
## 15 c d 0.5641686 0.74624317
## 16 a e 0.4559801 -0.65367306
## 17 b d 1.2309537 0.65710598
## 18 c e 1.1471368 0.54990924
## 19 a d 0.1065980 -0.80672936
## 20 b e -0.7833167 -0.99737972
## 21 c d 1.2411998 0.97589064
## 22 a e 0.1388584 -0.16942318
## 23 b d 1.7106316 0.72219178
## 24 c e -0.4306410 -0.84441861
## 25 a d -1.0442296 1.27729369
## 26 b e 0.5375795 -1.34311055
## 27 c d -0.6695860 0.76534067
## 28 a e 0.6388056 0.46420257
## 29 b d -1.7239898 0.26799328
## 30 c e -1.7424301 0.66752269