-
Notifications
You must be signed in to change notification settings - Fork 3
/
MSMpdfmultinormal.R
40 lines (33 loc) · 1.45 KB
/
MSMpdfmultinormal.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# ------------------------------------------------------------------------------
# Course: MSM - Selected Topics of Mathematical Statistics
# ------------------------------------------------------------------------------
# Quantlet: MSMpdfmultinormal
# ------------------------------------------------------------------------------
# Description: plot multimornal density function
# ------------------------------------------------------------------------------
# Usage:
# ------------------------------------------------------------------------------
# Inputs:
# ------------------------------------------------------------------------------
# Output:
# ------------------------------------------------------------------------------
# Keywords: multinormal density
# ------------------------------------------------------------------------------
# See also:
# ------------------------------------------------------------------------------
# Author: Xiu Xu 20150603
# ------------------------------------------------------------------------------
graphics.off()
rm(list=ls()) #remove variable definitions
#Load required packages
library(MASS)
getwd()
setwd("")
bivn <- mvrnorm(1000, mu = c(0, 0), Sigma = matrix(c(1, .5, .5, 1), 2))
# kernel density estimate
bivn.kde <- kde2d(bivn[,1], bivn[,2], n = 50)
# plot your results
name=paste("Fig_MSMpdfmultinormal",".pdf",sep="")
pdf(name)
persp(bivn.kde, phi = 45, theta = 30, xlab="X1", ylab="X2", zlab="PDF")
dev.off()