# Assignment 2 Meghna Khanna Question 1 Plain text 1 Calculate probability and conditional probability of an event

Assignment 2

Meghna Khanna

Question 1

Plain text 1 Calculate probability and conditional probability of an event (2 marks)

An accident victim arrived at a hospital,who will dieunless receive one bag of Rh-positive type A (A+) blood within the next 20 minutes. The blood bank in the hospital have a total 40 bags of blood and 2 bags are A+ blood. However, it is known that the blood type information of the blood bank was missing. So the nurse would need to re-type the bloods. It takes 2 minutes to examine the blood type of a bag of blood and 2 minutes to complete the transfer of blood. The hospital staff can only examine one bag of blood at a time. If the first bag of blood examined is not A+, the staff will examine the second bag, if not, the staff will examine the thrid bag. . . untill he/she is running out of time for saving the patient. . (a) What is the probability that the accident victim will be saved in this condition (1 mark).

Probability?Of?Success=1-Probability?Of?Failures(1-(38/40*37/39*36/38*35/37*34/36*33/35*32/34*31/33*30/32))

## 1 0.4038462

(b) What is the probability that the victim will not be saved given the A+ blood was not found in the first 10 minutes (1 mark).

So,number of bags that are left are 35 as the first 10 minutes have passed by, and 2 minutes for blood transfer so he has 8 minutes remaining, and 2 minutes for checking each bag, so the help can only check 4 bags.So, the chances of him dying are:

Probability?that?the?victim?will?not?be?saved?given?the?A+?blood=33/35*32/34*31/33*30/32(33/35*32/34*31/33*30/32)

## 1 0.7815126

2 PDF and expectation (3 Marks)

Let X have the pdf f(x) = 3x^2 for 0 < x < 1 and zero elsewhere.

. (a) Find E(X)

E(X)=01x*f(x)?=01?3*x3=0.75## . (b) Find Var(X)

Var(X)=E(X)2=01?3*x4=0.752=0.0375# . (c) Find E(X^3)

E(X3)=01?3×5=0.5#Question 3 Was it evidence of a problem in the area, or was it a chance? Can you verify this? Would Binomial or Poisson distribution be suitable for modeling this case?

Probability?of?12?leukemia?cases=Poisson(12,3.5)=e?*?xx!=0.000213dpois(12,3.5)

## 1 0.000213034

Answer: The answer is that even though poisson’s distribution tends to infinity, Binomial is basically a subset of Poisson’s as Binomial is for smaller ranges of values and this has a population of 35,000, so it could probably be both, but as Binomial is literally a subset of Poisson’s that’s why Poisson’s is a more suitable model for this case of leukemia.The probability of 12 people dying annualy even though the average annual rate is 3.5 gives us evidence that this happened because of a problem in that area.

Question 4

Calculate P(Survived) and P(Survived|Plcass = 1) using R. The value 1 of the “Survived” variable means survived, 0 means not survived (1 mark).

df ;- read.csv(“titanic.csv”)df

## X Survived Pclass Sex Embarked Survived_guess1 Survived_guess2## 1 1 0 3 male S 0 0## 2 2 1 1 female C 1 1## 3 3 1 3 female S 0 0## 4 4 1 1 female S 1 1## 5 5 0 3 male S 0 0## 6 6 0 3 male Q 0 0## 7 7 0 1 male S 1 1## 8 8 0 3 male S 0 0## 9 9 1 3 female S 0 0## 10 10 1 2 female C 1 1## 11 11 1 3 female S 0 0## 12 12 1 1 female S 1 1## 13 13 0 3 male S 0 0## 14 14 0 3 male S 0 0## 15 15 0 3 female S 0 0## 16 16 1 2 female S 0 1## 17 17 0 3 male Q 0 0## 18 18 1 2 male S 0 1## 19 19 0 3 female S 0 0## 20 20 1 3 female C 0 0## 21 21 0 2 male S 0 1## 22 22 1 2 male S 0 1## 23 23 1 3 female Q 0 0## 24 24 1 1 male S 1 1## 25 25 0 3 female S 0 0## 26 26 1 3 female S 0 0## 27 27 0 3 male C 0 0## 28 28 0 1 male S 1 1## 29 29 1 3 female Q 0 0## 30 30 0 3 male S 0 0## 31 31 0 1 male C 1 1## 32 32 1 1 female C 1 1## 33 33 1 3 female Q 0 0## 34 34 0 2 male S 0 1## 35 35 0 1 male C 1 1## 36 36 0 1 male S 1 1## 37 37 1 3 male C 0 0## 38 38 0 3 male S 0 0## 39 39 0 3 female S 0 0## 40 40 1 3 female C 0 0## 41 41 0 3 female S 0 0## 42 42 0 2 female S 0 1## 43 43 0 3 male C 0 0## 44 44 1 2 female C 1 1## 45 45 1 3 female Q 0 0## 46 46 0 3 male S 0 0## 47 47 0 3 male Q 0 0## 48 48 1 3 female Q 0 0## 49 49 0 3 male C 0 0## 50 50 0 3 female S 0 0## 51 51 0 3 male S 0 0## 52 52 0 3 male S 0 0## 53 53 1 1 female C 1 1## 54 54 1 2 female S 0 1## 55 55 0 1 male C 1 1## 56 56 1 1 male S 1 1## 57 57 1 2 female S 0 1## 58 58 0 3 male C 0 0## 59 59 1 2 female S 0 1## 60 60 0 3 male S 0 0## 61 61 0 3 male C 0 0## 62 62 1 1 female 1 1## 63 63 0 1 male S 1 1## 64 64 0 3 male S 0 0## 65 65 0 1 male C 1 1## 66 66 1 3 male C 0 0## 67 67 1 2 female S 0 1## 68 68 0 3 male S 0 0## 69 69 1 3 female S 0 0## 70 70 0 3 male S 0 0## 71 71 0 2 male S 0 1## 72 72 0 3 female S 0 0## 73 73 0 2 male S 0 1## 74 74 0 3 male C 0 0## 75 75 1 3 male S 0 0## 76 76 0 3 male S 0 0## 77 77 0 3 male S 0 0## 78 78 0 3 male S 0 0## 79 79 1 2 male S 0 1## 80 80 1 3 female S 0 0## 81 81 0 3 male S 0 0## 82 82 1 3 male S 0 0## 83 83 1 3 female Q 0 0## 84 84 0 1 male S 1 1## 85 85 1 2 female S 0 1## 86 86 1 3 female S 0 0## 87 87 0 3 male S 0 0## 88 88 0 3 male S 0 0## 89 89 1 1 female S 1 1## 90 90 0 3 male S 0 0## 91 91 0 3 male S 0 0## 92 92 0 3 male S 0 0## 93 93 0 1 male S 1 1## 94 94 0 3 male S 0 0## 95 95 0 3 male S 0 0## 96 96 0 3 male S 0 0## 97 97 0 1 male C 1 1## 98 98 1 1 male C 1 1## 99 99 1 2 female S 0 1## 100 100 0 2 male S 0 1## 101 101 0 3 female S 0 0## 102 102 0 3 male S 0 0## 103 103 0 1 male S 1 1## 104 104 0 3 male S 0 0## 105 105 0 3 male S 0 0## 106 106 0 3 male S 0 0## 107 107 1 3 female S 0 0## 108 108 1 3 male S 0 0## 109 109 0 3 male S 0 0## 110 110 1 3 female Q 0 0## 111 111 0 1 male S 1 1## 112 112 0 3 female C 0 0## 113 113 0 3 male S 0 0## 114 114 0 3 female S 0 0## 115 115 0 3 female C 0 0## 116 116 0 3 male S 0 0## 117 117 0 3 male Q 0 0## 118 118 0 2 male S 0 1## 119 119 0 1 male C 1 1## 120 120 0 3 female S 0 0## 121 121 0 2 male S 0 1## 122 122 0 3 male S 0 0## 123 123 0 2 male C 1 1## 124 124 1 2 female S 0 1## 125 125 0 1 male S 1 1## 126 126 1 3 male C 0 0## 127 127 0 3 male Q 0 0## 128 128 1 3 male S 0 0## 129 129 1 3 female C 0 0## 130 130 0 3 male S 0 0## 131 131 0 3 male C 0 0## 132 132 0 3 male S 0 0## 133 133 0 3 female S 0 0## 134 134 1 2 female S 0 1## 135 135 0 2 male S 0 1## 136 136 0 2 male C 1 1## 137 137 1 1 female S 1 1## 138 138 0 1 male S 1 1## 139 139 0 3 male S 0 0## 140 140 0 1 male C 1 1## 141 141 0 3 female C 0 0## 142 142 1 3 female S 0 0## 143 143 1 3 female S 0 0## 144 144 0 3 male Q 0 0## 145 145 0 2 male S 0 1## 146 146 0 2 male S 0 1## 147 147 1 3 male S 0 0## 148 148 0 3 female S 0 0## 149 149 0 2 male S 0 1## 150 150 0 2 male S 0 1## 151 151 0 2 male S 0 1## 152 152 1 1 female S 1 1## 153 153 0 3 male S 0 0## 154 154 0 3 male S 0 0## 155 155 0 3 male S 0 0## 156 156 0 1 male C 1 1## 157 157 1 3 female Q 0 0## 158 158 0 3 male S 0 0## 159 159 0 3 male S 0 0## 160 160 0 3 male S 0 0## 161 161 0 3 male S 0 0## 162 162 1 2 female S 0 1## 163 163 0 3 male S 0 0## 164 164 0 3 male S 0 0## 165 165 0 3 male S 0 0## 166 166 1 3 male S 0 0## 167 167 1 1 female S 1 1## 168 168 0 3 female S 0 0## 169 169 0 1 male S 1 1## 170 170 0 3 male S 0 0## 171 171 0 1 male S 1 1## 172 172 0 3 male Q 0 0## 173 173 1 3 female S 0 0## 174 174 0 3 male S 0 0## 175 175 0 1 male C 1 1## 176 176 0 3 male S 0 0## 177 177 0 3 male S 0 0## 178 178 0 1 female C 1 1## 179 179 0 2 male S 0 1## 180 180 0 3 male S 0 0## 181 181 0 3 female S 0 0## 182 182 0 2 male C 1 1## 183 183 0 3 male S 0 0## 184 184 1 2 male S 0 1## 185 185 1 3 female S 0 0## 186 186 0 1 male S 1 1## 187 187 1 3 female Q 0 0## 188 188 1 1 male S 1 1## 189 189 0 3 male Q 0 0## 190 190 0 3 male S 0 0## 191 191 1 2 female S 0 1## 192 192 0 2 male S 0 1## 193 193 1 3 female S 0 0## 194 194 1 2 male S 0 1## 195 195 1 1 female C 1 1## 196 196 1 1 female C 1 1## 197 197 0 3 male Q 0 0## 198 198 0 3 male S 0 0## 199 199 1 3 female Q 0 0## 200 200 0 2 female S 0 1## 201 201 0 3 male S 0 0## 202 202 0 3 male S 0 0## 203 203 0 3 male S 0 0## 204 204 0 3 male C 0 0## 205 205 1 3 male S 0 0## 206 206 0 3 female S 0 0## 207 207 0 3 male S 0 0## 208 208 1 3 male C 0 0## 209 209 1 3 female Q 0 0## 210 210 1 1 male C 1 1## 211 211 0 3 male S 0 0## 212 212 1 2 female S 0 1## 213 213 0 3 male S 0 0## 214 214 0 2 male S 0 1## 215 215 0 3 male Q 0 0## 216 216 1 1 female C 1 1## 217 217 1 3 female S 0 0## 218 218 0 2 male S 0 1## 219 219 1 1 female C 1 1## 220 220 0 2 male S 0 1## 221 221 1 3 male S 0 0## 222 222 0 2 male S 0 1## 223 223 0 3 male S 0 0## 224 224 0 3 male S 0 0## 225 225 1 1 male S 1 1## 226 226 0 3 male S 0 0## 227 227 1 2 male S 0 1## 228 228 0 3 male S 0 0## 229 229 0 2 male S 0 1## 230 230 0 3 female S 0 0## 231 231 1 1 female S 1 1## 232 232 0 3 male S 0 0## 233 233 0 2 male S 0 1## 234 234 1 3 female S 0 0## 235 235 0 2 male S 0 1## 236 236 0 3 female S 0 0## 237 237 0 2 male S 0 1## 238 238 1 2 female S 0 1## 239 239 0 2 male S 0 1## 240 240 0 2 male S 0 1## 241 241 0 3 female C 0 0## 242 242 1 3 female Q 0 0## 243 243 0 2 male S 0 1## 244 244 0 3 male S 0 0## 245 245 0 3 male C 0 0## 246 246 0 1 male Q 1 1## 247 247 0 3 female S 0 0## 248 248 1 2 female S 0 1## 249 249 1 1 male S 1 1## 250 250 0 2 male S 0 1## 251 251 0 3 male S 0 0## 252 252 0 3 female S 0 0## 253 253 0 1 male S 1 1## 254 254 0 3 male S 0 0## 255 255 0 3 female S 0 0## 256 256 1 3 female C 0 0## 257 257 1 1 female C 1 1## 258 258 1 1 female S 1 1## 259 259 1 1 female C 1 1## 260 260 1 2 female S 0 1## 261 261 0 3 male Q 0 0## 262 262 1 3 male S 0 0## 263 263 0 1 male S 1 1## 264 264 0 1 male S 1 1## 265 265 0 3 female Q 0 0## 266 266 0 2 male S 0 1## 267 267 0 3 male S 0 0## 268 268 1 3 male S 0 0## 269 269 1 1 female S 1 1## 270 270 1 1 female S 1 1## 271 271 0 1 male S 1 1## 272 272 1 3 male S 0 0## 273 273 1 2 female S 0 1## 274 274 0 1 male C 1 1## 275 275 1 3 female Q 0 0## 276 276 1 1 female S 1 1## 277 277 0 3 female S 0 0## 278 278 0 2 male S 0 1## 279 279 0 3 male Q 0 0## 280 280 1 3 female S 0 0## 281 281 0 3 male Q 0 0## 282 282 0 3 male S 0 0## 283 283 0 3 male S 0 0## 284 284 1 3 male S 0 0## 285 285 0 1 male S 1 1## 286 286 0 3 male C 0 0## 287 287 1 3 male S 0 0## 288 288 0 3 male S 0 0## 289 289 1 2 male S 0 1## 290 290 1 3 female Q 0 0## 291 291 1 1 female S 1 1## 292 292 1 1 female C 1 1## 293 293 0 2 male C 1 1## 294 294 0 3 female S 0 0## 295 295 0 3 male S 0 0## 296 296 0 1 male C 1 1## 297 297 0 3 male C 0 0## 298 298 0 1 female S 1 1## 299 299 1 1 male S 1 1## 300 300 1 1 female C 1 1## 301 301 1 3 female Q 0 0## 302 302 1 3 male Q 0 0## 303 303 0 3 male S 0 0## 304 304 1 2 female Q 1 1## 305 305 0 3 male S 0 0## 306 306 1 1 male S 1 1## 307 307 1 1 female C 1 1## 308 308 1 1 female C 1 1## 309 309 0 2 male C 1 1## 310 310 1 1 female C 1 1## 311 311 1 1 female C 1 1## 312 312 1 1 female C 1 1## 313 313 0 2 female S 0 1## 314 314 0 3 male S 0 0## 315 315 0 2 male S 0 1## 316 316 1 3 female S 0 0## 317 317 1 2 female S 0 1## 318 318 0 2 male S 0 1## 319 319 1 1 female S 1 1## 320 320 1 1 female C 1 1## 321 321 0 3 male S 0 0## 322 322 0 3 male S 0 0## 323 323 1 2 female Q 1 1## 324 324 1 2 female S 0 1## 325 325 0 3 male S 0 0## 326 326 1 1 female C 1 1## 327 327 0 3 male S 0 0## 328 328 1 2 female S 0 1## 329 329 1 3 female S 0 0## 330 330 1 1 female C 1 1## 331 331 1 3 female Q 0 0## 332 332 0 1 male S 1 1## 333 333 0 1 male S 1 1## 334 334 0 3 male S 0 0## 335 335 1 1 female S 1 1## 336 336 0 3 male S 0 0## 337 337 0 1 male S 1 1## 338 338 1 1 female C 1 1## 339 339 1 3 male S 0 0## 340 340 0 1 male S 1 1## 341 341 1 2 male S 0 1## 342 342 1 1 female S 1 1## 343 343 0 2 male S 0 1## 344 344 0 2 male S 0 1## 345 345 0 2 male S 0 1## 346 346 1 2 female S 0 1## 347 347 1 2 female S 0 1## 348 348 1 3 female S 0 0## 349 349 1 3 male S 0 0## 350 350 0 3 male S 0 0## 351 351 0 3 male S 0 0## 352 352 0 1 male S 1 1## 353 353 0 3 male C 0 0## 354 354 0 3 male S 0 0## 355 355 0 3 male C 0 0## 356 356 0 3 male S 0 0## 357 357 1 1 female S 1 1## 358 358 0 2 female S 0 1## 359 359 1 3 female Q 0 0## 360 360 1 3 female Q 0 0## 361 361 0 3 male S 0 0## 362 362 0 2 male C 1 1## 363 363 0 3 female C 0 0## 364 364 0 3 male S 0 0## 365 365 0 3 male Q 0 0## 366 366 0 3 male S 0 0## 367 367 1 1 female C 1 1## 368 368 1 3 female C 0 0## 369 369 1 3 female Q 0 0## 370 370 1 1 female C 1 1## 371 371 1 1 male C 1 1## 372 372 0 3 male S 0 0## 373 373 0 3 male S 0 0## 374 374 0 1 male C 1 1## 375 375 0 3 female S 0 0## 376 376 1 1 female C 1 1## 377 377 1 3 female S 0 0## 378 378 0 1 male C 1 1## 379 379 0 3 male C 0 0## 380 380 0 3 male S 0 0## 381 381 1 1 female C 1 1## 382 382 1 3 female C 0 0## 383 383 0 3 male S 0 0## 384 384 1 1 female S 1 1## 385 385 0 3 male S 0 0## 386 386 0 2 male S 0 1## 387 387 0 3 male S 0 0## 388 388 1 2 female S 0 1## 389 389 0 3 male Q 0 0## 390 390 1 2 female C 1 1## 391 391 1 1 male S 1 1## 392 392 1 3 male S 0 0## 393 393 0 3 male S 0 0## 394 394 1 1 female C 1 1## 395 395 1 3 female S 0 0## 396 396 0 3 male S 0 0## 397 397 0 3 female S 0 0## 398 398 0 2 male S 0 1## 399 399 0 2 male S 0 1## 400 400 1 2 female S 0 1## 401 401 1 3 male S 0 0## 402 402 0 3 male S 0 0## 403 403 0 3 female S 0 0## 404 404 0 3 male S 0 0## 405 405 0 3 female S 0 0## 406 406 0 2 male S 0 1## 407 407 0 3 male S 0 0## 408 408 1 2 male S 0 1## 409 409 0 3 male S 0 0## 410 410 0 3 female S 0 0## 411 411 0 3 male S 0 0## 412 412 0 3 male Q 0 0## 413 413 1 1 female Q 1 1## 414 414 0 2 male S 0 1## 415 415 1 3 male S 0 0## 416 416 0 3 female S 0 0## 417 417 1 2 female S 0 1## 418 418 1 2 female S 0 1## 419 419 0 2 male S 0 1## 420 420 0 3 female S 0 0## 421 421 0 3 male C 0 0## 422 422 0 3 male Q 0 0## 423 423 0 3 male S 0 0## 424 424 0 3 female S 0 0## 425 425 0 3 male S 0 0## 426 426 0 3 male S 0 0## 427 427 1 2 female S 0 1## 428 428 1 2 female S 0 1## 429 429 0 3 male Q 0 0## 430 430 1 3 male S 0 0## 431 431 1 1 male S 1 1## 432 432 1 3 female S 0 0## 433 433 1 2 female S 0 1## 434 434 0 3 male S 0 0## 435 435 0 1 male S 1 1## 436 436 1 1 female S 1 1## 437 437 0 3 female S 0 0## 438 438 1 2 female S 0 1## 439 439 0 1 male S 1 1## 440 440 0 2 male S 0 1## 441 441 1 2 female S 0 1## 442 442 0 3 male S 0 0## 443 443 0 3 male S 0 0## 444 444 1 2 female S 0 1## 445 445 1 3 male S 0 0## 446 446 1 1 male S 1 1## 447 447 1 2 female S 0 1## 448 448 1 1 male S 1 1## 449 449 1 3 female C 0 0## 450 450 1 1 male S 1 1## 451 451 0 2 male S 0 1## 452 452 0 3 male S 0 0## 453 453 0 1 male C 1 1## 454 454 1 1 male C 1 1## 455 455 0 3 male S 0 0## 456 456 1 3 male C 0 0## 457 457 0 1 male S 1 1## 458 458 1 1 female S 1 1## 459 459 1 2 female S 0 1## 460 460 0 3 male Q 0 0## 461 461 1 1 male S 1 1## 462 462 0 3 male S 0 0## 463 463 0 1 male S 1 1## 464 464 0 2 male S 0 1## 465 465 0 3 male S 0 0## 466 466 0 3 male S 0 0## 467 467 0 2 male S 0 1## 468 468 0 1 male S 1 1## 469 469 0 3 male Q 0 0## 470 470 1 3 female C 0 0## 471 471 0 3 male S 0 0## 472 472 0 3 male S 0 0## 473 473 1 2 female S 0 1## 474 474 1 2 female C 1 1## 475 475 0 3 female S 0 0## 476 476 0 1 male S 1 1## 477 477 0 2 male S 0 1## 478 478 0 3 male S 0 0## 479 479 0 3 male S 0 0## 480 480 1 3 female S 0 0## 481 481 0 3 male S 0 0## 482 482 0 2 male S 0 1## 483 483 0 3 male S 0 0## 484 484 1 3 female S 0 0## 485 485 1 1 male C 1 1## 486 486 0 3 female S 0 0## 487 487 1 1 female S 1 1## 488 488 0 1 male C 1 1## 489 489 0 3 male S 0 0## 490 490 1 3 male S 0 0## 491 491 0 3 male S 0 0## 492 492 0 3 male S 0 0## 493 493 0 1 male S 1 1## 494 494 0 1 male C 1 1## 495 495 0 3 male S 0 0## 496 496 0 3 male C 0 0## 497 497 1 1 female C 1 1## 498 498 0 3 male S 0 0## 499 499 0 1 female S 1 1## 500 500 0 3 male S 0 0## 501 501 0 3 male S 0 0## 502 502 0 3 female Q 0 0## 503 503 0 3 female Q 0 0## 504 504 0 3 female S 0 0## 505 505 1 1 female S 1 1## 506 506 0 1 male C 1 1## 507 507 1 2 female S 0 1## 508 508 1 1 male S 1 1## 509 509 0 3 male S 0 0## 510 510 1 3 male S 0 0## 511 511 1 3 male Q 0 0## 512 512 0 3 male S 0 0## 513 513 1 1 male S 1 1## 514 514 1 1 female C 1 1## 515 515 0 3 male S 0 0## 516 516 0 1 male S 1 1## 517 517 1 2 female S 0 1## 518 518 0 3 male Q 0 0## 519 519 1 2 female S 0 1## 520 520 0 3 male S 0 0## 521 521 1 1 female S 1 1## 522 522 0 3 male S 0 0## 523 523 0 3 male C 0 0## 524 524 1 1 female C 1 1## 525 525 0 3 male C 0 0## 526 526 0 3 male Q 0 0## 527 527 1 2 female S 0 1## 528 528 0 1 male S 1 1## 529 529 0 3 male S 0 0## 530 530 0 2 male S 0 1## 531 531 1 2 female S 0 1## 532 532 0 3 male C 0 0## 533 533 0 3 male C 0 0## 534 534 1 3 female C 0 0## 535 535 0 3 female S 0 0## 536 536 1 2 female S 0 1## 537 537 0 1 male S 1 1## 538 538 1 1 female C 1 1## 539 539 0 3 male S 0 0## 540 540 1 1 female C 1 1## 541 541 1 1 female S 1 1## 542 542 0 3 female S 0 0## 543 543 0 3 female S 0 0## 544 544 1 2 male S 0 1## 545 545 0 1 male C 1 1## 546 546 0 1 male S 1 1## 547 547 1 2 female S 0 1## 548 548 1 2 male C 1 1## 549 549 0 3 male S 0 0## 550 550 1 2 male S 0 1## 551 551 1 1 male C 1 1## 552 552 0 2 male S 0 1## 553 553 0 3 male Q 0 0## 554 554 1 3 male C 0 0## 555 555 1 3 female S 0 0## 556 556 0 1 male S 1 1## 557 557 1 1 female C 1 1## 558 558 0 1 male C 1 1## 559 559 1 1 female S 1 1## 560 560 1 3 female S 0 0## 561 561 0 3 male Q 0 0## 562 562 0 3 male S 0 0## 563 563 0 2 male S 0 1## 564 564 0 3 male S 0 0## 565 565 0 3 female S 0 0## 566 566 0 3 male S 0 0## 567 567 0 3 male S 0 0## 568 568 0 3 female S 0 0## 569 569 0 3 male C 0 0## 570 570 1 3 male S 0 0## 571 571 1 2 male S 0 1## 572 572 1 1 female S 1 1## 573 573 1 1 male S 1 1## 574 574 1 3 female Q 0 0## 575 575 0 3 male S 0 0## 576 576 0 3 male S 0 0## 577 577 1 2 female S 0 1## 578 578 1 1 female S 1 1## 579 579 0 3 female C 0 0## 580 580 1 3 male S 0 0## 581 581 1 2 female S 0 1## 582 582 1 1 female C 1 1## 583 583 0 2 male S 0 1## 584 584 0 1 male C 1 1## 585 585 0 3 male C 0 0## 586 586 1 1 female S 1 1## 587 587 0 2 male S 0 1## 588 588 1 1 male C 1 1## 589 589 0 3 male S 0 0## 590 590 0 3 male S 0 0## 591 591 0 3 male S 0 0## 592 592 1 1 female C 1 1## 593 593 0 3 male S 0 0## 594 594 0 3 female Q 0 0## 595 595 0 2 male S 0 1## 596 596 0 3 male S 0 0## 597 597 1 2 female S 0 1## 598 598 0 3 male S 0 0## 599 599 0 3 male C 0 0## 600 600 1 1 male C 1 1## 601 601 1 2 female S 0 1## 602 602 0 3 male S 0 0## 603 603 0 1 male S 1 1## 604 604 0 3 male S 0 0## 605 605 1 1 male C 1 1## 606 606 0 3 male S 0 0## 607 607 0 3 male S 0 0## 608 608 1 1 male S 1 1## 609 609 1 2 female C 1 1## 610 610 1 1 female S 1 1## 611 611 0 3 female S 0 0## 612 612 0 3 male S 0 0## 613 613 1 3 female Q 0 0## 614 614 0 3 male Q 0 0## 615 615 0 3 male S 0 0## 616 616 1 2 female S 0 1## 617 617 0 3 male S 0 0## 618 618 0 3 female S 0 0## 619 619 1 2 female S 0 1## 620 620 0 2 male S 0 1## 621 621 0 3 male C 0 0## 622 622 1 1 male S 1 1## 623 623 1 3 male C 0 0## 624 624 0 3 male S 0 0## 625 625 0 3 male S 0 0## 626 626 0 1 male S 1 1## 627 627 0 2 male Q 1 1## 628 628 1 1 female S 1 1## 629 629 0 3 male S 0 0## 630 630 0 3 male Q 0 0## 631 631 1 1 male S 1 1## 632 632 0 3 male S 0 0## 633 633 1 1 male C 1 1## 634 634 0 1 male S 1 1## 635 635 0 3 female S 0 0## 636 636 1 2 female S 0 1## 637 637 0 3 male S 0 0## 638 638 0 2 male S 0 1## 639 639 0 3 female S 0 0## 640 640 0 3 male S 0 0## 641 641 0 3 male S 0 0## 642 642 1 1 female C 1 1## 643 643 0 3 female S 0 0## 644 644 1 3 male S 0 0## 645 645 1 3 female C 0 0## 646 646 1 1 male C 1 1## 647 647 0 3 male S 0 0## 648 648 1 1 male C 1 1## 649 649 0 3 male S 0 0## 650 650 1 3 female S 0 0## 651 651 0 3 male S 0 0## 652 652 1 2 female S 0 1## 653 653 0 3 male S 0 0## 654 654 1 3 female Q 0 0## 655 655 0 3 female Q 0 0## 656 656 0 2 male S 0 1## 657 657 0 3 male S 0 0## 658 658 0 3 female Q 0 0## 659 659 0 2 male S 0 1## 660 660 0 1 male C 1 1## 661 661 1 1 male S 1 1## 662 662 0 3 male C 0 0## 663 663 0 1 male S 1 1## 664 664 0 3 male S 0 0## 665 665 1 3 male S 0 0## 666 666 0 2 male S 0 1## 667 667 0 2 male S 0 1## 668 668 0 3 male S 0 0## 669 669 0 3 male S 0 0## 670 670 1 1 female S 1 1## 671 671 1 2 female S 0 1## 672 672 0 1 male S 1 1## 673 673 0 2 male S 0 1## 674 674 1 2 male S 0 1## 675 675 0 2 male S 0 1## 676 676 0 3 male S 0 0## 677 677 0 3 male S 0 0## 678 678 1 3 female S 0 0## 679 679 0 3 female S 0 0## 680 680 1 1 male C 1 1## 681 681 0 3 female Q 0 0## 682 682 1 1 male C 1 1## 683 683 0 3 male S 0 0## 684 684 0 3 male S 0 0## 685 685 0 2 male S 0 1## 686 686 0 2 male C 1 1## 687 687 0 3 male S 0 0## 688 688 0 3 male S 0 0## 689 689 0 3 male S 0 0## 690 690 1 1 female S 1 1## 691 691 1 1 male S 1 1## 692 692 1 3 female C 0 0## 693 693 1 3 male S 0 0## 694 694 0 3 male C 0 0## 695 695 0 1 male S 1 1## 696 696 0 2 male S 0 1## 697 697 0 3 male S 0 0## 698 698 1 3 female Q 0 0## 699 699 0 1 male C 1 1## 700 700 0 3 male S 0 0## 701 701 1 1 female C 1 1## 702 702 1 1 male S 1 1## 703 703 0 3 female C 0 0## 704 704 0 3 male Q 0 0## 705 705 0 3 male S 0 0## 706 706 0 2 male S 0 1## 707 707 1 2 female S 0 1## 708 708 1 1 male S 1 1## 709 709 1 1 female S 1 1## 710 710 1 3 male C 0 0## 711 711 1 1 female C 1 1## 712 712 0 1 male S 1 1## 713 713 1 1 male S 1 1## 714 714 0 3 male S 0 0## 715 715 0 2 male S 0 1## 716 716 0 3 male S 0 0## 717 717 1 1 female C 1 1## 718 718 1 2 female S 0 1## 719 719 0 3 male Q 0 0## 720 720 0 3 male S 0 0## 721 721 1 2 female S 0 1## 722 722 0 3 male S 0 0## 723 723 0 2 male S 0 1## 724 724 0 2 male S 0 1## 725 725 1 1 male S 1 1## 726 726 0 3 male S 0 0## 727 727 1 2 female S 0 1## 728 728 1 3 female Q 0 0## 729 729 0 2 male S 0 1## 730 730 0 3 female S 0 0## 731 731 1 1 female S 1 1## 732 732 0 3 male C 0 0## 733 733 0 2 male S 0 1## 734 734 0 2 male S 0 1## 735 735 0 2 male S 0 1## 736 736 0 3 male S 0 0## 737 737 0 3 female S 0 0## 738 738 1 1 male C 1 1## 739 739 0 3 male S 0 0## 740 740 0 3 male S 0 0## 741 741 1 1 male S 1 1## 742 742 0 1 male S 1 1## 743 743 1 1 female C 1 1## 744 744 0 3 male S 0 0## 745 745 1 3 male S 0 0## 746 746 0 1 male S 1 1## 747 747 0 3 male S 0 0## 748 748 1 2 female S 0 1## 749 749 0 1 male S 1 1## 750 750 0 3 male Q 0 0## 751 751 1 2 female S 0 1## 752 752 1 3 male S 0 0## 753 753 0 3 male S 0 0## 754 754 0 3 male S 0 0## 755 755 1 2 female S 0 1## 756 756 1 2 male S 0 1## 757 757 0 3 male S 0 0## 758 758 0 2 male S 0 1## 759 759 0 3 male S 0 0## 760 760 1 1 female S 1 1## 761 761 0 3 male S 0 0## 762 762 0 3 male S 0 0## 763 763 1 3 male C 0 0## 764 764 1 1 female S 1 1## 765 765 0 3 male S 0 0## 766 766 1 1 female S 1 1## 767 767 0 1 male C 1 1## 768 768 0 3 female Q 0 0## 769 769 0 3 male Q 0 0## 770 770 0 3 male S 0 0## 771 771 0 3 male S 0 0## 772 772 0 3 male S 0 0## 773 773 0 2 female S 0 1## 774 774 0 3 male C 0 0## 775 775 1 2 female S 0 1## 776 776 0 3 male S 0 0## 777 777 0 3 male Q 0 0## 778 778 1 3 female S 0 0## 779 779 0 3 male Q 0 0## 780 780 1 1 female S 1 1## 781 781 1 3 female C 0 0## 782 782 1 1 female S 1 1## 783 783 0 1 male S 1 1## 784 784 0 3 male S 0 0## 785 785 0 3 male S 0 0## 786 786 0 3 male S 0 0## 787 787 1 3 female S 0 0## 788 788 0 3 male Q 0 0## 789 789 1 3 male S 0 0## 790 790 0 1 male C 1 1## 791 791 0 3 male Q 0 0## 792 792 0 2 male S 0 1## 793 793 0 3 female S 0 0## 794 794 0 1 male C 1 1## 795 795 0 3 male S 0 0## 796 796 0 2 male S 0 1## 797 797 1 1 female S 1 1## 798 798 1 3 female S 0 0## 799 799 0 3 male C 0 0## 800 800 0 3 female S 0 0## 801 801 0 2 male S 0 1## 802 802 1 2 female S 0 1## 803 803 1 1 male S 1 1## 804 804 1 3 male C 0 0## 805 805 1 3 male S 0 0## 806 806 0 3 male S 0 0## 807 807 0 1 male S 1 1## 808 808 0 3 female S 0 0## 809 809 0 2 male S 0 1## 810 810 1 1 female S 1 1## 811 811 0 3 male S 0 0## 812 812 0 3 male S 0 0## 813 813 0 2 male S 0 1## 814 814 0 3 female S 0 0## 815 815 0 3 male S 0 0## 816 816 0 1 male S 1 1## 817 817 0 3 female S 0 0## 818 818 0 2 male C 1 1## 819 819 0 3 male S 0 0## 820 820 0 3 male S 0 0## 821 821 1 1 female S 1 1## 822 822 1 3 male S 0 0## 823 823 0 1 male S 1 1## 824 824 1 3 female S 0 0## 825 825 0 3 male S 0 0## 826 826 0 3 male Q 0 0## 827 827 0 3 male S 0 0## 828 828 1 2 male C 1 1## 829 829 1 3 male Q 0 0## 830 830 1 1 female 1 1## 831 831 1 3 female C 0 0## 832 832 1 2 male S 0 1## 833 833 0 3 male C 0 0## 834 834 0 3 male S 0 0## 835 835 0 3 male S 0 0## 836 836 1 1 female C 1 1## 837 837 0 3 male S 0 0## 838 838 0 3 male S 0 0## 839 839 1 3 male S 0 0## 840 840 1 1 male C 1 1## 841 841 0 3 male S 0 0## 842 842 0 2 male S 0 1## 843 843 1 1 female C 1 1## 844 844 0 3 male C 0 0## 845 845 0 3 male S 0 0## 846 846 0 3 male S 0 0## 847 847 0 3 male S 0 0## 848 848 0 3 male C 0 0## 849 849 0 2 male S 0 1## 850 850 1 1 female C 1 1## 851 851 0 3 male S 0 0## 852 852 0 3 male S 0 0## 853 853 0 3 female C 0 0## 854 854 1 1 female S 1 1## 855 855 0 2 female S 0 1## 856 856 1 3 female S 0 0## 857 857 1 1 female S 1 1## 858 858 1 1 male S 1 1## 859 859 1 3 female C 0 0## 860 860 0 3 male C 0 0## 861 861 0 3 male S 0 0## 862 862 0 2 male S 0 1## 863 863 1 1 female S 1 1## 864 864 0 3 female S 0 0## 865 865 0 2 male S 0 1## 866 866 1 2 female S 0 1## 867 867 1 2 female C 1 1## 868 868 0 1 male S 1 1## 869 869 0 3 male S 0 0## 870 870 1 3 male S 0 0## 871 871 0 3 male S 0 0## 872 872 1 1 female S 1 1## 873 873 0 1 male S 1 1## 874 874 0 3 male S 0 0## 875 875 1 2 female C 1 1## 876 876 1 3 female C 0 0## 877 877 0 3 male S 0 0## 878 878 0 3 male S 0 0## 879 879 0 3 male S 0 0## 880 880 1 1 female C 1 1## 881 881 1 2 female S 0 1## 882 882 0 3 male S 0 0## 883 883 0 3 female S 0 0## 884 884 0 2 male S 0 1## 885 885 0 3 male S 0 0## 886 886 0 3 female Q 0 0## 887 887 0 2 male S 0 1## 888 888 1 1 female S 1 1## 889 889 0 3 female S 0 0## 890 890 1 1 male C 1 1## 891 891 0 3 male Q 0 0

P(Survived)is:Number?Of?Survived?PassengersTotal?number?of?passengers=0.3838new1 ;- which(df$Survived==1)x;-length(new1)y;-nrow(df)x/y

## 1 0.3838384

P(Survived|Pclass=1)is:Number?Of?Survived?Passengers?in?Pclass?=?1Total?number?of?Pclass=1?Passengers=0.6296296newdata ;- subset(df, Survived == 1 ; Pclass ==1, select=Sex:Survived_guess2)inter;-nrow(newdata)PClass;- which(df$Pclass==1)Class;-length(PClass)inter/Class

## 1 0.6296296

b) Calculate the entropy (log2()) of H(Embarked) and H(P class).Which entropy is higher? Why?

Do not use an entropy function. (1 mark)

newest ;- which(df$Survived==1)x;-length(new1)

$$H(K)= sum_{i=1}^n P_i * log_2 (frac{1}{P_i}) \ where K is the dimension of p $$

H(Embarked)=P(C)*log2(1Pc)+P(Q)*log2(1PQ)+P(S)*log2(1PS)=1.117393for (i in 1:4) x ;- table(df$Embarked)/891-sum(x * log2(x))

## 1 1.117393

y ;- table(df$Pclass)/891 -sum(y * log2(y))

## 1 1.439321

In this competition, you must predict the fate of the passengers aboard the Titanic. Caroline used two methods to predict survival of passengers. She saved the prediction results as variable “Survived_guess1” and “Survived_guess2”. Calculate H(Survived_guess1|P class) and H(Survived_guess2|Pclass),which entropy is higher? (1 mark)} H(Survived_guess1|P class) and Survived_guess2 given Pclass

H(X|Y)=YEyp(Y=y)H(X|YEy)$$ H(Survivedguess1|Pclass)=0.1024223 \H(Survivedguess2|Pclass)=0 \H(Survived guess1|Pclass) has higher entropy than H(Survivedguess2|Pclass)$$

p;-0prob;-0sum1;-0sum2;-0for(i in 1:3){ p;-subset(df,Pclass== i) f;-table(p$Survived_guess1)/length(p$Pclass) H;- -sum(f*log2(f)) * (length(p$Pclass)/length(df$Pclass)) sum1 ;- sum1 + H prob;-subset(df,Pclass== i) f1;-table(prob$Survived_guess2)/length(prob$Pclass) H1;- -sum(f1*log2(f1)) * (length(prob$Pclass)/length(df$Pclass)) sum2 ;- sum2 + H1}sum1

## 1 0.1024223

sum2

## 1 0

(d) (d) Can you guess which algorithm that Caroline used to obtain the prediction Survived_guess2. Hint:

she used two variables Pclass and Embarked 2 in prediction. (optional with 1 bonus marks)

df;-subset(df, Pclass==1,Embarked)df

## Embarked## 2 C## 4 S## 7 S## 12 S## 24 S## 28 S## 31 C## 32 C## 35 C## 36 S## 53 C## 55 C## 56 S## 62 ## 63 S## 65 C## 84 S## 89 S## 93 S## 97 C## 98 C## 103 S## 111 S## 119 C## 125 S## 137 S## 138 S## 140 C## 152 S## 156 C## 167 S## 169 S## 171 S## 175 C## 178 C## 186 S## 188 S## 195 C## 196 C## 210 C## 216 C## 219 C## 225 S## 231 S## 246 Q## 249 S## 253 S## 257 C## 258 S## 259 C## 263 S## 264 S## 269 S## 270 S## 271 S## 274 C## 276 S## 285 S## 291 S## 292 C## 296 C## 298 S## 299 S## 300 C## 306 S## 307 C## 308 C## 310 C## 311 C## 312 C## 319 S## 320 C## 326 C## 330 C## 332 S## 333 S## 335 S## 337 S## 338 C## 340 S## 342 S## 352 S## 357 S## 367 C## 370 C## 371 C## 374 C## 376 C## 378 C## 381 C## 384 S## 391 S## 394 C## 413 Q## 431 S## 435 S## 436 S## 439 S## 446 S## 448 S## 450 S## 453 C## 454 C## 457 S## 458 S## 461 S## 463 S## 468 S## 476 S## 485 C## 487 S## 488 C## 493 S## 494 C## 497 C## 499 S## 505 S## 506 C## 508 S## 513 S## 514 C## 516 S## 521 S## 524 C## 528 S## 537 S## 538 C## 540 C## 541 S## 545 C## 546 S## 551 C## 556 S## 557 C## 558 C## 559 S## 572 S## 573 S## 578 S## 582 C## 584 C## 586 S## 588 C## 592 C## 600 C## 603 S## 605 C## 608 S## 610 S## 622 S## 626 S## 628 S## 631 S## 633 C## 634 S## 642 C## 646 C## 648 C## 660 C## 661 S## 663 S## 670 S## 672 S## 680 C## 682 C## 690 S## 691 S## 695 S## 699 C## 701 C## 702 S## 708 S## 709 S## 711 C## 712 S## 713 S## 717 C## 725 S## 731 S## 738 C## 741 S## 742 S## 743 C## 746 S## 749 S## 760 S## 764 S## 766 S## 767 C## 780 S## 782 S## 783 S## 790 C## 794 C## 797 S## 803 S## 807 S## 810 S## 816 S## 821 S## 823 S## 830 ## 836 C## 840 C## 843 C## 850 C## 854 S## 857 S## 858 S## 863 S## 868 S## 872 S## 873 S## 880 C## 888 S## 890 C

Answer: So,basically all people from Pclass dies, and Pclass 1 and 2 have survived, since in the original titanic also the first and second class were saved first not the third class people.

Question 5

One of the central problems of sensory neuroscience is to separate the recordings of background physiological processes that are irrelevant (noise), from neural responses that are of experimental interest (signal). This is by no means an easy task, as the signals that neurons produce when they fire are extremely weak and more random. It is therefore of particular interest to examine the randomness of neuro signals as this allows researchers to study the brain at a cellular level. (a) Let’s assume that we have conducted one experiment and recorded the spike signals from one particular neuron for a duration of time. After some data processing, we can obtain spike signals similar to the following figure. If the rate of the signals remains constant over time, Which distribution would most suit to model the probability distribution for the number of spike signals over a period of time? Why? Briefly answer this question in a sentence or 2. (1 mark)

Answer:

A Poisson experiment is a statistical experiment that has the following properties: Poisson distribution is most suitable to model the probability distribution for the number of spike signals distribution over a period of time as Poisson distribution is used for predicting the probability when the average number of successes (X) are known, and the rate of the signals stay constant over time,which is a characteristic of Poisson’s,and all the n trials are independant of each other, and the actual mean is compared with the observed mean of the distribution,in order to generate the maximum likelihood of the function.

(b) The researcher repeated the experiment for n times, in each time he/she recorded the number

of spike signals Xn for 10ms. Each experiment was independent from the other. The researcher decided to use the Poisson distribution to model this outcome. What is the log-likelihood function for number of spike signals for the period of experiment time? (1 mark)

$$L(lambda,x_1,x_2,…..,x_n)= prod_{j=1}^n frac {e^{-lambda} *lambda^{x_i}}{x_i!} \ where x_1 x_2 …. x_n are values of observation \ n=10 $$

$$l(lambda,x_1,x_2,…..,x_n)= sum_{i=1}^{n}log(e^{-lambda}) +sum_{i=1}^{n}log(lambda^{x_i}) \ from the figure 11 signals in 10ms therefore lambda=11(Considering 10ms as one interval) \=-n10 + log(11)sum_{i=1}^{n}x_i$$

Answer: The log likelihood function is basically log(Lambda + Xi* Lambda), where X is the average of the sample of the observations that is 11 spike signals per 10ms, as observed in the diagram, and Lambda is the mean that should have been of the experiment, the actual mean.So,basically this estimator for Poisson Distribution is derived from the Poissson’s formula(e^-lambda*Lamda^x)/x!, this then taken the log of, as integrating the multiplication would be abhrd so we took a log so we could sum it and find the maximum liklelihood of 11 spike signals appearing every 10ms for n number of trials.

If n = 10 and recorded number of spike signals were: 5, 6, 10, 9, 8, 7, 8, 7, 10, 11. Obtain MLE

for the mean number of signals. Hint: You can define the ML function in R and then use the optimize() function to find the optimal parameters for the given dataset. (Optional: 1 bonus mark)

y<-c(5, 6, 10, 9, 8, 7, 8, 7, 10, 11)mean.likelihood<-function(x,par) -sum(log(dpois(x,par)))result<-optimize(mean.likelihood, c(1,10), x=y) result$minimum

## 1 8.099994

result

## $minimum## 1 8.099994## ## $objective## 1 21.69824

6 Central Limit Theorem (4 marks)

Assume that we draw random numbers from a normal distribution with mean ยต = 5, variance = 10.

(a) According to Central Limit Theorem what is the sample mean and SE when we have sample size of 10, 100, 1000 and 10000? (1 marks)

mean_1<-5variance<-10samples<-c(10,100,1000,10000)standard_err<-sqrt(variance)/sqrt(samples) standard_err

## 1 1.00000000 0.31622777 0.10000000 0.03162278

print(“The sample mean is same as the population mean”)

## 1 “The sample mean is same as the population mean”

(b) Experimentally justify the Central Limit Theorem using simulation given sample a size of 10,

100 and 1000 (for each given sample size you can use 50000 simulations to explore the sampling distribution of the mean ) (1 marks)

sample?mean(?x)?=?population?mean(?)$$SE= SD/ sqrt(n) \where SD is Standard Deviation, SD=sqrt(variance) n is sample size$$

mean1<-rep(NA,50000)for (i in 1:50000) { mean1i<-mean(rnorm(10,5,sqrt(10)))}hist(x=mean1,freq=FALSE,xlab=”Average of the sample”,main=”Histogram for 10 samples”)

rm(list=ls())

mean2<-rep(NA,50000)for (i in 1:50000) { mean2i<-mean(rnorm(100,5,sqrt(10)))}hist(x=mean2,freq=FALSE,xlab=”Average of the sample”,main=”Histogram for 100 samples”)

rm(list=ls())

mean3<-rep(NA,50000)for (i in 1:50000) {mean3i<-mean(rnorm(1000,5,sqrt(10)))}hist(x=mean3,freq=FALSE,xlab=”Average of the sample”,main=”Histogram for 1000 samples”)

mean4<-rep(NA,50000)for (i in 1:50000) {mean4i<-mean(rnorm(10000,5,sqrt(10)))}hist(x=mean4,freq=FALSE,xlab=”Average of the sample”,main=”Histogram for 10,000 samples”)

(c) When sample size is 10, obtain the t scores and z scores of the sampling means (from 50000 simulations). Plot the distributions in a histogram with the theoretical Gaussian curve and t-distribution (9 degrees of freedom). For t score and z score, which of the theoretical curve fits better? Why?(2 marks)

var1<-10sigma<-sqrt(var1)mu<-5x<-c()zscore<-c()degf<-9tscore<-c()for (i in 1:50000) {x<-rnorm(10,5,sigma)zscore<<-c(zscore,((mean(x)-mu)/(sigma/sqrt(10))))tscore<<-c(tscore,((mean(x)-mu)/(sd(x)/sqrt(10))))}hist(zscore,freq=FALSE,probability = TRUE,ylim = c(0,0.4))curve( dt(x,df=9),add=TRUE, col=’green’)curve(dnorm(x,0,sqrt(10)/sqrt(10)),add=TRUE,col=’orange’)legend(“topright”, c(“Gaussian”, “TDistribution”), col=c(“green”, “orange”), lwd=10)

hist(tscore,freq=FALSE,probability=TRUE,ylim = c(0,0.4))curve( dt(x,df=9),add=TRUE, col=’green’)curve(dnorm(x,0,sqrt(10)/sqrt(10)),add=TRUE,col=’orange’)legend(“topright”, c(“Gaussian”, “TDistribution”), col=c(“green”, “orange”), lwd=10)

# Answer: For zscore a gaussian distribution fits better as it has same standard deviation per sample and for tscore the standard deviation varies per sample so T Distributuion fits better for tscore.