-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinnie.Rmd
231 lines (113 loc) · 3.19 KB
/
Winnie.Rmd
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
---
title: "Lab 4"
author: "Winnie Ngare"
output:
html_document:
toc: yes
html_notebook:
toc: yes
toc_float: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
##Qn 1:Normal distribution.
###No. of points(x) in a tournament are **normally distributed with a **mean =32 & sd=7
### 20 points or fewer(x<=20)
```{r}
pnorm(20,mean = 32,sd=7)
#####Density function.
curve(dnorm(x,mean = 32,sd=7),from = 11, to=53)
norm.x <- c(11,seq(11,20,by=0.01),20)
norm.y <- c(0,dnorm(seq(11,20,0.01),mean = 32,sd=7),0)
polygon(norm.x,norm.y,col = "blue")
```
###b)more than 35 points.
```{r}
####More than 35 points.
pnorm(35,mean = 32,sd=7,lower.tail = FALSE)
####density function
curve(dnorm(x,mean = 32,sd=7),from = 11, to=53)
x.cord <- c(35,seq(35,53,0.01),53)
y.cord <- c(0,dnorm(seq(35,53,0.01),mean = 32,sd=7),0)
polygon(x.cord,y.cord,col = "blue")
```
###c)Team scoring between 20 and 40 points.
```{r}
pnorm(40,mean = 32,sd=7)-pnorm(20,mean = 32,sd=7)
####density function
curve(dnorm(x,mean = 32,sd=7),from=11,to=53)
x <- c(20,seq(20,40,0.01),40)
y <- c(0,dnorm(seq(20,40,0.01),mean = 32,sd=7),0)
polygon(x,y,col = "blue")
```
##Q2;Exponential distribution.
###a)Fewer than 3 comments;
```{r, warning=FALSE}
pexp(3,0.1) ####25.91% get less than 3 comments
```
###density function
```{r, message=FALSE, warning=FALSE}
curve(dexp(x,0.1),from=0,to=90)
x <- c(0,seq(0, 3, 0.1),3)
y <- c(0,dexp(seq(0, 3, 0.1), 0.1),0)
polygon(x,y,col = "blue")
```
###b)more than 20 comments
```{r, message=FALSE, warning=FALSE}
pexp(20,0.1,lower.tail = FALSE) ####13.53% get more than 20 comments.
curve(dexp(x,0.1),from=0,to=90)
x <- c(20,seq(20,90,0.1),90)
y <- c(0,dexp(seq(20,90,0.1),0.1),0)
polygon(x,y,col = "blue")
```
###C)between 5 and 10 comments
```{r}
pexp(10,0.1)-pexp(5,0.1) #### 23.86% get between 5 and 10 comments.
curve(dexp(x,0.1),from=0,to=90)
x <- c(5,seq(5,10,0.1),10)
y <- c(0,dexp(seq(5,10,0.1),0.1),0)
polygon(x,y,col = "blue")
```
##Q3; Basic Raster creation and calculation:
###Raster of runif distribution.(30*30)
```{r, message=FALSE, warning=FALSE}
library(raster)
ras1 <- raster(nrows=30,ncols=30,xmn=0,xmx=30,ymn=0,ymx=30)
ras1
set.seed(10)
ras1[] <- runif(ncell(ras1))
plot(ras1)
hist(ras1)
```
###raster of a rnorm distribution.(30*30)
```{r}
ras2 <- raster(nrows=30,ncols=30,xmn=0,xmx=30,ymn=0,ymx=30)
ras2
set.seed(100)
ras2[] <- rnorm(ncell(ras2))
plot(ras2)
hist(ras2)
```
###third raster(additional)
```{r}
ras.add <- ras1+ ras2
ras.add
plot(ras.add)
hist(ras.add)
```
###Mean of third raster.
```{r}
rasmean <- cellStats(ras.add,"mean")
rasmean
```
###reclassifying 3rd raster and saving it to the directory.
```{r, message=FALSE, warning=FALSE}
library(rgdal)
ras.add[ras.add>rasmean] <- 1
ras.add[ras.add <=rasmean] <- 0
plot(ras.add)
hist(ras.add)
writeRaster(ras.add, filename = "thirdraster.tif", overwrite=T)
read=raster("thirdraster.tif")
```