-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek3 Ex.R
108 lines (66 loc) · 2.74 KB
/
Week3 Ex.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
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
#WEEK THREE EXERCISE: ERRORS
# Q1 ----------------------------------------------------------------------
#converting the units
torad <- function(d, m, s) { rad <- pi* (d+m/60+s/3600/180)
return(rad)}
#the angle between the horizontal plane and the building to be 1°21’
#the distance to a building is estimated from a map to be about 2550 25 m
angle <- torad(1, 21, 0)
angle_err <- torad(0, 1, 0)
d <- 2550
d_err <- 25
#What is the height of the building and the fractional uncertainty in this estimate?
#equation is height = d*tan(angle)
height <- d*tan(angle)
print(height)
height_err <- d_err*tan(angle_err)
print(height_err)
#uncertainty
un <- height_err/abs(height)
print(un)
# Q2 ----------------------------------------------------------------------
#Volcano 1: 25.53 plus or minus 0.1 Ma
#volcano 2: 29.66 plus or minus 0.2
v1 <- 25.53
v1_err <- 0.1
v2 <- 29.66
v2_err <- 0.2
#Duration of the volcanic activity? We use differences equation
#min x-y + delta x + delta y and min x-y-delta x - delta y
max <- v1-v2+v1_err+v2_err
min <- v1-v2-v1_err-v2_err
print (min)
print(max)
# Q3 ----------------------------------------------------------------------
# Import the file ---------------------------------------------------------
Earthquake <- read.csv(('ex3_eqscals.txt'), header = FALSE, sep="", col.names = c("distance,km", "radius,m" ,"moments,Nm"))
View(Earthquake)
distance <- Earthquake$distance.km
radius <- Earthquake$radius.m
moments <- Earthquake$moments.Nm
# Q1A ---------------------------------------------------------------------
#What is the mean, median, standard deviation, and median absolute deviation (MAD) for r and Mo?
#For R
mean_r <- mean(radius)
median_r <- median(radius)
sd_r <- sd(radius)
MAD_r <- mad(radius)
#for Mo
mean_m <- mean(moments)
median_m <- median(moments)
sd_m <- sd(moments)
MAD_m <- mad(moments)
# Q3B ---------------------------------------------------------------------
#For r
plot(Earthquake$radius ,xlim = c(1,20), ylim = c(300,2000), ylab = "Value" ,xlab = "Radius in m" ,main = "Earthquake Radius value" ,col="red")
#For Mo
plot(Earthquake$moments.Nm, Earthquake$distance, ylab = "Distance in km" ,xlab = "Moments in Nm", main = "Earthquake Moments value with regards to the distance" ,col="blue")
# Q3C ---------------------------------------------------------------------
newdata <- subset(Earthquake[Earthquake$moments.Nm<3*MAD_m,])
View(newdata)
mean_newdata_Mo <- mean(newdata$moments.Nm)
median_newdata_Mo <- median(newdata$moments.Nm)
sd_newdata_Mo <- sd(newdata$moments.Nm
)
MAD_newdata_Mo <- mad(newdata$moments.Nm)
#I did not understand this question :(