-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass2_script.R
More file actions
executable file
·129 lines (109 loc) · 2.08 KB
/
Class2_script.R
File metadata and controls
executable file
·129 lines (109 loc) · 2.08 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
### some data
dat1=c(0,0,0,100,100,100)
dat2=c(49,49,49,51,51,51)
dat3=c(0,10,20,80,90,100)
dat4=c(50,50,50,50,50,50)
dat5=c(0,0,10,80,80,90,90,80,10,100)
dat6=c("Cont","KO","Cont","KO","KO","KO","Control")
### central tendencies
mean(dat1)
median(dat1)
mean(dat2)
median(dat2)
mean(dat3)
median(dat3)
mean(dat4)
median(dat4)
mean(dat5)
median(dat5)
mean(dat6)
median(dat6)
mode(dat1) # doesn't do what we expect.
dat1
table(dat1)
sort(table(dat1))
sort(table(dat2))
sort(table(dat3))
sort(table(dat4))
sort(table(dat5))
sort(table(dat6))
## variation
range(dat1)
IQR(dat1)
sd(dat1)
var(dat1)
sqrt(var(dat1))
sd(dat1)^2
range(dat2)
IQR(dat2)
sd(dat2)
var(dat2)
range(dat3)
IQR(dat3)
sd(dat3)
var(dat3)
range(dat4)
IQR(dat4)
sd(dat4)
var(dat4)
range(dat5)
IQR(dat5)
sd(dat5)
var(dat5)
range(dat6)
IQR(dat6)
sd(dat6)
var(dat6)
plot(dat1)
hist(dat1,xlim=c(0,100),ylim=c(0,5))
hist(dat2,xlim=c(0,100),ylim=c(0,5))
hist(dat3,xlim=c(0,100),ylim=c(0,5))
hist(dat4,xlim=c(0,100),ylim=c(0,5))
hist(dat5,xlim=c(0,100),ylim=c(0,5))
hist(dat6,xlim=c(0,100),ylim=c(0,5))
barplot(table(dat6),col=c("red","blue","green"))
dev.off()
par(mar=c(2,2,2,2))
par(mfrow=c(2,2))
hist(dat1,xlim=c(0,100),ylim=c(0,5))
hist(dat2,xlim=c(0,100),ylim=c(0,5))
hist(dat3,xlim=c(0,100),ylim=c(0,5))
hist(dat5,xlim=c(0,100),ylim=c(0,5))
summary(dat1)
summary(dat2)
summary(dat3)
summary(dat4)
summary(dat5)
summary(dat6)
#### Let's look at some more realistic data
## we can simulate data by randomly sampling from known distributions
dev.off()
ex1=rnorm(10000,0,1)
hist(ex1,breaks=100)
mean(ex1)
sd(ex1)
newdata1=rnorm(1000,50,10)
newdata2=rnorm(500,25,5)
newdata3=rnorm(500,75,5)
newdata4=c(newdata2,newdata3)
summary(newdata1)
hist(newdata1,breaks=50)
summary(newdata2)
hist(newdata2,breaks=50)
summary(newdata3)
hist(newdata3,breaks=50)
summary(newdata4)
hist(newdata4,breaks=50)
newdata5=runif(1000,0,100)
hist(newdata5)
summary(newdata5)
newdata6=rbeta(1000,2,5,0)
hist(newdata6)
summary(newdata6)
newdata7=rgamma(1000,10)
hist(newdata7)
summary(newdata7)
newdata8=rnbinom(1000,300,0.3)
hist(newdata8)
summary(newdata8)
sessionInfo()