-
Notifications
You must be signed in to change notification settings - Fork 1
/
1.2 Basic Stat commands (Albert) (pp 2-8).txt
80 lines (43 loc) · 1.43 KB
/
1.2 Basic Stat commands (Albert) (pp 2-8).txt
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
##Basic statistics on "studentdata"
##we use studentdata in LearnBayes
library("LearnBayes")
#access the data by:
data(studentdata)
#to see variable names
studentdata[1, ]
#to see the top 5 observations:
head(studentdata)
#to see the bottom 5 observations:
tail(studentdata)
#attach (make visible) the data to the R environment
attach(studentdata)
#without attach, you need to use studentdata$"variable name" for all requests
#to tally responses in categorical variable Drink
table(Drink)
#without using attach, you need to use table(studentdata$Drink)
#construct bar plot
barplot(table(Drink), xlab = "Drink", ylab="Count")
#compute new variable
hours.of.sleep=WakeUp-ToSleep
#descriptive statistics
summary(hours.of.sleep)
#construct histogram
hist(hours.of.sleep,main="")
#compare with
hist(hours.of.sleep) #see change in heading
#get boxplot of hours.of.sleep per gender
boxplot(hours.of.sleep~Gender, ylab="Hours of Sleep")
#create variable per category
female.Haircut=Haircut[Gender=="female"]
male.Haircut=Haircut[Gender=="male"]
#get summary of these new variables
summary(female.Haircut)
summary(male.Haircut)
boxplot(Haircut~Gender,ylab="Haircut")
#R commands for studying relationships
plot(jitter(ToSleep),jitter(hours.of.sleep))
#Try removing jitter
plot((ToSleep),(hours.of.sleep))
fit=(lm(hours.of.sleep~ToSleep
fit
abline(fit)