R Markdown

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.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(MASS)

#make this example reproducible
set.seed(0)

#simulate bivariate normal distribution
bivariate_data2 <- as.data.frame(mvrnorm(n=100,
                                        mu=c(0, 0),
                                        Sigma=matrix(c(5, 3, 4, 4), ncol=2)))

#view first six rows of bivariate dataset
head(bivariate_data2)
##            V1         V2
## 1 -2.03600343 -2.9623059
## 2  0.07719131  1.2948982
## 3 -3.26729701 -1.7928069
## 4 -2.62985132 -2.3015471
## 5 -1.75126215  0.3056698
## 6  3.67698436  2.2020238
print (bivariate_data2)
##               V1          V2
## 1   -2.036003431 -2.96230585
## 2    0.077191314  1.29489820
## 3   -3.267297006 -1.79280690
## 4   -2.629851319 -2.30154711
## 5   -1.751262148  0.30566984
## 6    3.676984357  2.20202377
## 7    0.945879603  2.82849217
## 8    1.886451838 -0.97474650
## 9   -0.378783529  0.47164110
## 10  -3.728486253 -5.81496521
## 11  -1.922046101 -0.97526740
## 12   0.915208484  2.31426518
## 13   2.424584695  2.01375454
## 14   0.627978563  0.48848879
## 15  -0.684664350  2.07945024
## 16   1.684877459 -0.24060586
## 17  -1.402515274  0.58402926
## 18   2.130906500  1.27392276
## 19  -0.526657622 -1.22932480
## 20   2.700875299  2.06947030
## 21   0.377190106  0.50755585
## 22  -0.636462810 -0.85206598
## 23  -1.113662486  0.74814799
## 24  -2.312104022 -0.68729390
## 25  -0.749798775  1.12772890
## 26   0.178249174 -2.35002090
## 27  -1.105822343 -3.30756840
## 28   1.652839787  0.98444157
## 29   1.729252779  3.41637306
## 30  -0.100815533 -0.07950984
## 31   1.673977453 -0.97465250
## 32   0.766200416  1.40201987
## 33   1.530838823  0.03384690
## 34   0.600532039  2.05040995
## 35  -0.984656383 -1.92529066
## 36  -3.159858979 -1.16386886
## 37  -3.040476048 -0.62608356
## 38   0.152994263  1.64420523
## 39  -3.273703534 -1.39652227
## 40  -0.125586576  1.33506727
## 41  -3.104786786 -3.80346528
## 42  -1.121488858 -1.05848588
## 43   0.696015897  1.10205716
## 44   0.895264455  2.47815520
## 45   1.651317397  3.00692114
## 46   1.633435777  2.59901102
## 47   2.402599342  3.80763638
## 48  -2.773242913 -1.63990441
## 49  -1.375188995 -1.91163955
## 50  -0.445209531  1.49137006
## 51   0.590096446 -1.82728400
## 52  -0.234425416  1.87717112
## 53  -5.190921737 -4.24458762
## 54   3.516449810 -0.77199000
## 55   0.810254756 -0.72332385
## 56  -0.721005731 -0.21161976
## 57  -1.971307291 -0.29958872
## 58   0.816505366 -0.23045229
## 59   4.650119759  3.95907427
## 60   2.355113865  2.58841308
## 61  -0.503513939 -0.92970020
## 62  -0.358440851  0.47005253
## 63   4.046487596 -0.78032130
## 64   1.554403455 -1.34282182
## 65   2.316244366  0.72820237
## 66   0.049157567 -1.08729763
## 67   2.562312997  3.02989597
## 68  -0.075301867 -1.46582912
## 69  -0.792646998 -0.11970572
## 70  -0.923739112  0.81305721
## 71   1.429963315 -1.76940203
## 72  -1.264419529  0.39928166
## 73   1.130254309  1.42313277
## 74  -0.230356818  0.77822183
## 75  -2.130945101 -0.30611890
## 76  -1.839352136 -2.50624240
## 77  -1.490662139  1.14884700
## 78   0.085776642  0.39902639
## 79   1.462800811  2.14819169
## 80   1.927048868  3.83285540
## 81   1.615228731  1.47976294
## 82  -2.964137323 -1.82899086
## 83  -2.080245636 -0.82483881
## 84   1.225873721 -0.51447179
## 85   1.305760450  0.26343017
## 86   0.807305210  0.82706701
## 87  -1.966895408 -1.91390863
## 88   0.002276799  1.16896971
## 89  -2.789004675 -2.04395199
## 90  -0.494611912 -2.16356018
## 91  -2.735618521 -2.29090687
## 92   1.956109932  1.40098939
## 93   1.563086094 -1.88072573
## 94   1.296417230  2.21206035
## 95  -0.499344228 -1.94378151
## 96   1.146885850 -1.86248001
## 97  -0.239479095  1.48152607
## 98  -3.037070965 -2.60070078
## 99  -0.784262964 -0.04721032
## 100 -2.471299038 -1.31659829
library(mnormt)

#make this example reproducible
set.seed(0)

#create bivariate normal distribution
x     <- seq(-3, 3, 0.1) 
y     <- seq(-3, 3, 0.1)
mu    <- c(0, 0)
sigma <- matrix(c(2, -1, -1, 2), nrow=2)
f     <- function(x, y) dmnorm(cbind(x, y), mu, sigma)
z     <- outer(x, y, f)

#create contour plot
contour(x, y, z)

library(mnormt)

#make this example reproducible
set.seed(0)

#create bivariate normal distribution
x     <- seq(-3, 3, 0.1) 
y     <- seq(-3, 3, 0.1)
mu    <- c(0, 0)
sigma <- matrix(c(2, -1, -1, 2), nrow=2)
f     <- function(x, y) dmnorm(cbind(x, y), mu, sigma)
z     <- outer(x, y, f)

#create surface plot
persp(x, y, z, theta=-30, phi=25, expand=0.6, ticktype='detailed')

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.