-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment-4.R
73 lines (51 loc) · 1.71 KB
/
Assignment-4.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
# ----- 1. Aspirin & Heart Attacks -----
# import data
data <- read.csv("C:/Users/maddy/OneDrive/Desktop/Assignment 5 - Data.csv")
x <- (data) # data table
x # print data table
test <- chisq.test(data) # test statistic
test # print t-statistic
# ----- 2a. Reading a Newspaper -----
# data values
female <- c(5,3,6,3,7,1,1,3,0,4,7,2,2,7,3,0,5,0,4,4,5,14,3,1,2,1,7,2,5,3,7)
male <- c(0,3,7,4,3,2,1,12,1,6,2,2,7,7,5,3,14,3,7,6,5,5,2,3,5,5,2,3,3)
# create dot plots
stripchart(female,
main = "Number of Times Reading a Newspaper",
xlab = "Females",
method = "stack",
pch = 20,
cex = 2,
at = 0.1,
col = "pink1"
)
stripchart(male,
# main = "Number of Times Reading a Newspaper",
xlab = "Males",
method = "stack",
pch = 20,
cex = 2,
at = 0.1,
col = "lightblue2"
)
# ----- 2b. Calculate 95% Interval -----
summary(female)
sd(female)
summary(male)
sd(male)
t.test(female, male, conf.level = 0.95)
# ----- 3. Textbooks -----
# data values
a <- c(115,79,43,140,99,30,80,99,119,69)
b <- c(110,79,40,129,99,30,69,99,109,66)
t.test(a,b, conf.level = 0.90)
# boxplot
# sex <- factor(WORKERS1000$SEX, levels = c(1,2), labels = c("Site A", "Site B"))
boxplot(a,b,
main = "Population Distribution of Site A and B",
names = c("Site A", "Site B"),
xlab = "Textbook Prices ($)",
ylab = "Internet Bookstores",
horizontal = TRUE,
col = c("ivory", "cornsilk")
)