forked from theofpa/datascience
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek4-videos.R
82 lines (70 loc) · 1.13 KB
/
week4-videos.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# str()
str(str)
str(lm)
str(ls)
x<-rnorm(100,2,4)
summary(x)
str(x)
f<-gl(40,10)
str(f)
summary(f)
library(datasets)
head(airquality)
str(airquality)
m<-matrix(rnorm(100),10,10)
str(m)
s<-split(airquality,airquality$Month)
str(s)
# Simulation
# rnorm, dnorm, pnorm, rpois
# d-density r-random p-cumulative q-quantile
dnorm(x,mean=0,sd=1,log=FALSE)
pnorm(x,mean=0,sd=1,lower.tail=TRUE,log.p=FALSE)
qnorm(x,mean=0,sd=1,lower.tail=TRUE,log.p=FALSE)
rnorm(x,mean=0,sd=1)
x<-rnorm(10)
x<-rnorm(10,20,2)
summary(x)
set.seed(1)
rnorm(5)
set.seed(1)
rnorm(5)
rpois(10,1)
rpois(10,2)
rpois(10,20)
ppois(2,2)
ppois(4,2)
ppois(6,2)
set.seed(20)
x<-rnorm(100)
e<-rnorm(100,0,2)
y<-0.5 + 2*x +e
summary(y)
plot(x,y)
set.seed(10)
x<-rbinom(100,1,0.5)
e<-rnorm(100,0,2)
y<-0.5 + 2*x +e
summary(y)
plot(x,y)
set.seed(1)
x<-rnorm(100)
log.mu<-0.5+0.3*x
y<-rpois(100,exp(log.mu))
summary(y)
plot(x,y)
set.seed(1)
sample(1:10,4)
sample(1:10,4)
sample(letters,5)
sample(1:10)
sample(1:10)
sample(1:10,replace=TRUE)
# Profiling
system.time(readLines("http://www.jhsph.edu"))
hilbert<-function(n){
i<-1:n
1/outer(i-1,i,"+")
}
x<-hilbert(1000)
system.time(svd(x))