︠dc8f8424-7b27-46df-b997-dd6a43bd405fs︠ %r pnorm(260.5, mean=272, sd=9) qnorm(0.10, mean=272, sd=9) ︡fb378f75-99ba-48e7-8326-af1d2e786353︡{"html":"0.100663895991501"}︡{"html":"260.466035910099"}︡{"done":true}︡ ︠de1158fa-5295-4d5d-be4e-1758730df9c9︠ %r x<-c(83, 51, 87, 60, 28, 95, 8, 27, 15, 10, 18, 16, 29, 54, 91, 8, 17, 55, 10, 35, 47, 77, 36, 17, 21, 36, 18, 40, 10, 7, 34, 27, 28, 56, 8, 25, 68, 146, 89, 18, 73, 69, 9, 37, 10, 82, 29, 8, 60, 61, 61, 18, 169, 25, 8, 26, 11, 83, 11, 42, 17, 14, 9, 12) #print(x) hist(x,nclass=7) qt = quantile(x) print(qt) sprintf("Q1 = %2.2f",qt[1]) IQR = qt[4]-qt[2] sprintf("IQR = %2.2f", IQR) Q1 = qt[2]; Q3 = qt[4]; sprintf("1.5*IQR = %2.2f", 1.5*IQR) out_rg1 = Q1-1.5*IQR out_rg2 = Q3+1.5*IQR sprintf("Q1-1.5*IQR = %2.2f", out_rg1) sprintf("Q3+1.5*IQR = %2.2f", out_rg2) print(x out_rg2 = %2.2f", sum(x>out_rg2)) sprintf("number of xp > out_rg2 = %2.2f", sum(xp>out_rg2)) xp1 = x[xout_rg2] print(xp1) #outliers below 1.5*Q1 print(xp2) #outliers above 1.5*Q3 qqnorm(x) ︡784c0864-10b1-467c-b353-88c1d806135c︡{"stdout":" 0% 25% 50% 75% 100% \n 7.00 14.75 28.00 60.00 169.00 \n"}︡{"html":"'Q1 = 7.00'"}︡{"html":"'IQR = 45.25'"}︡{"html":"'1.5*IQR = 67.88'"}︡{"html":"'Q1-1.5*IQR = -53.12'"}︡{"html":"'Q3+1.5*IQR = 127.88'"}︡{"stdout":" [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE\n[13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE\n[25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE\n[37] TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE\n[49] TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE\n[61] TRUE TRUE TRUE TRUE\n"}︡{"stdout":" [1] 83 51 87 60 28 95 8 27 15 10 18 16 29 54 91 8 17 55 10 35 47 77 36 17 21\n[26] 36 18 40 10 7 34 27 28 56 8 25 68 89 18 73 69 9 37 10 82 29 8 60 61 61\n[51] 18 25 8 26 11 83 11 42 17 14 9 12\n"}︡{"html":"'number of x > out_rg2 = 2.00'"}︡{"html":"'number of xp > out_rg2 = 0.00'"}︡{"stdout":"numeric(0)\n"}︡{"stdout":"[1] 146 169\n"}︡{"file":{"filename":"/tmp/tmpxdt1l_.png","show":false,"text":null,"uuid":"b194c4a4-de37-4e6d-a85a-244d1c051c4f"},"once":false}︡{"html":""}︡{"file":{"filename":"/tmp/tmpZ2Wq0J.png","show":false,"text":null,"uuid":"557df518-f0c6-4148-ab4f-fb7dfda1b708"},"once":false}︡{"html":""}︡{"done":true}︡ ︠1da7d3ec-8d12-4ce7-9200-5a0748e54e9cs︠ %r x<-c(78, 92, 96, 100, 67, 105, 109, 75, 127, 111, 93, 114, 82, 100, 125, 67, 94, 74, 81, 98, 102, 108, 81, 96, 103, 91, 90, 96, 86, 92, 84, 92, 90, 103, 115, 93, 85, 116, 87, 106, 85, 88, 106, 104, 102, 98, 116, 107, 102, 89) hist(x, nclass = 7) qt = quantile(x) print(qt) IQR = qt[4]-qt[2] sprintf("IQR = %2.2f", IQR) Q1 = qt[2]; Q3 = qt[4]; sprintf("1.5*IQR = %2.2f", 1.5*IQR) out_rg1 = Q1-1.5*IQR out_rg2 = Q3+1.5*IQR sprintf("Q1-1.5*IQR = %2.2f", out_rg1) sprintf("Q3+1.5*IQR = %2.2f", out_rg2) #print(x out_rg2 = %2.2f", sum(x>out_rg2)) sprintf("number of xp > out_rg2 = %2.2f", sum(xp>out_rg2)) xp1 = x[xout_rg2] print(xp1) #outliers below 1.5*Q1 print(xp2) #outliers above 1.5*Q3 qqnorm(x) ︡80a87e21-da9e-49e9-a874-827a53493fe6︡{"stdout":" 0% 25% 50% 75% 100% \n 67.00 87.25 96.00 104.75 127.00 \n"}︡{"html":"'IQR = 17.50'"}︡{"html":"'1.5*IQR = 26.25'"}︡{"html":"'Q1-1.5*IQR = 61.00'"}︡{"html":"'Q3+1.5*IQR = 131.00'"}︡{"html":"'number of x > out_rg2 = 0.00'"}︡{"html":"'number of xp > out_rg2 = 0.00'"}︡{"stdout":"numeric(0)\n"}︡{"stdout":"numeric(0)\n"}︡{"file":{"filename":"/tmp/tmpA8ZKAE.png","show":false,"text":null,"uuid":"a7803d84-26c3-4118-82b3-35f0a74cd916"},"once":false}︡{"html":""}︡{"file":{"filename":"/tmp/tmpSiDTkD.png","show":false,"text":null,"uuid":"9d71de7f-c9a4-48bc-8099-371360356e3e"},"once":false}︡{"html":""}︡{"done":true}︡ ︠5ec81cf1-86e4-4160-b6f7-b0c0c0c9a6f0s︠ %r #n=10; #x<-sample(c(0,1), replace=TRUE, size=n) #print(x) n=500 N = 500 X <-c() for (i in seq(1,N)){ X[i]<-mean(sample(c(0,1), replace=TRUE, size=n)) } print(X) hist(X) ︡ecf83ace-7f96-4a36-9e56-866d9df4e17f︡{"stdout":" [1] 0.532 0.472 0.520 0.474 0.478 0.500 0.498 0.514 0.520 0.492 0.510 0.496\n [13] 0.478 0.486 0.504 0.554 0.528 0.520 0.532 0.498 0.494 0.508 0.534 0.508\n [25] 0.504 0.462 0.490 0.516 0.518 0.478 0.476 0.484 0.490 0.528 0.486 0.506\n [37] 0.492 0.470 0.502 0.492 0.516 0.490 0.528 0.538 0.462 0.494 0.526 0.508\n [49] 0.502 0.492 0.464 0.476 0.506 0.506 0.526 0.492 0.474 0.518 0.474 0.524\n [61] 0.448 0.450 0.518 0.524 0.490 0.488 0.490 0.496 0.484 0.442 0.484 0.530\n [73] 0.494 0.534 0.484 0.492 0.524 0.528 0.542 0.498 0.474 0.548 0.482 0.504\n [85] 0.500 0.472 0.480 0.550 0.498 0.476 0.518 0.496 0.472 0.524 0.514 0.472\n [97] 0.482 0.422 0.500 0.520 0.484 0.532 0.446 0.496 0.484 0.512 0.532 0.500\n[109] 0.530 0.514 0.466 0.520 0.590 0.496 0.512 0.516 0.488 0.488 0.464 0.502\n[121] 0.494 0.518 0.514 0.510 0.538 0.506 0.510 0.468 0.514 0.492 0.476 0.496\n[133] 0.512 0.524 0.516 0.498 0.514 0.490 0.526 0.508 0.504 0.526 0.514 0.516\n[145] 0.516 0.482 0.506 0.462 0.518 0.480 0.524 0.520 0.520 0.476 0.500 0.466\n[157] 0.468 0.482 0.478 0.556 0.512 0.466 0.528 0.478 0.498 0.486 0.506 0.498\n[169] 0.522 0.540 0.538 0.520 0.542 0.518 0.454 0.514 0.512 0.492 0.528 0.494\n[181] 0.522 0.498 0.524 0.494 0.466 0.472 0.532 0.522 0.510 0.462 0.492 0.508\n[193] 0.496 0.514 0.504 0.484 0.492 0.506 0.532 0.530 0.490 0.456 0.516 0.508\n[205] 0.508 0.532 0.472 0.494 0.496 0.528 0.486 0.482 0.528 0.480 0.518 0.468\n[217] 0.532 0.536 0.486 0.488 0.474 0.516 0.516 0.500 0.520 0.510 0.484 0.508\n[229] 0.518 0.506 0.484 0.492 0.484 0.534 0.546 0.486 0.462 0.488 0.504 0.482\n[241] 0.534 0.462 0.518 0.512 0.496 0.522 0.516 0.472 0.490 0.496 0.498 0.486\n[253] 0.496 0.454 0.500 0.482 0.512 0.498 0.542 0.500 0.552 0.492 0.474 0.490\n[265] 0.526 0.488 0.480 0.546 0.478 0.506 0.520 0.496 0.508 0.472 0.470 0.504\n[277] 0.518 0.528 0.496 0.500 0.450 0.502 0.476 0.498 0.498 0.492 0.484 0.524\n[289] 0.508 0.496 0.470 0.474 0.444 0.456 0.504 0.498 0.522 0.464 0.484 0.500\n[301] 0.526 0.524 0.494 0.510 0.534 0.514 0.478 0.486 0.466 0.484 0.492 0.522\n[313] 0.502 0.506 0.518 0.490 0.506 0.480 0.512 0.470 0.522 0.500 0.470 0.514\n[325] 0.518 0.508 0.518 0.516 0.492 0.530 0.530 0.494 0.496 0.494 0.476 0.508\n[337] 0.490 0.544 0.490 0.472 0.514 0.490 0.504 0.528 0.502 0.528 0.528 0.488\n[349] 0.526 0.502 0.486 0.524 0.480 0.524 0.498 0.488 0.470 0.468 0.514 0.462\n[361] 0.524 0.514 0.516 0.502 0.474 0.532 0.506 0.480 0.498 0.492 0.478 0.512\n[373] 0.556 0.498 0.480 0.488 0.500 0.510 0.486 0.496 0.484 0.480 0.522 0.508\n[385] 0.490 0.548 0.498 0.514 0.478 0.524 0.460 0.512 0.504 0.464 0.526 0.492\n[397] 0.458 0.478 0.512 0.514 0.488 0.510 0.506 0.502 0.494 0.480 0.504 0.486\n[409] 0.478 0.440 0.536 0.512 0.514 0.510 0.478 0.504 0.500 0.490 0.464 0.488\n[421] 0.488 0.494 0.500 0.532 0.512 0.492 0.500 0.520 0.502 0.484 0.510 0.476\n[433] 0.484 0.494 0.496 0.504 0.494 0.546 0.498 0.548 0.506 0.488 0.458 0.498\n[445] 0.510 0.558 0.496 0.528 0.484 0.490 0.504 0.462 0.508 0.496 0.508 0.480\n[457] 0.514 0.494 0.518 0.532 0.522 0.472 0.538 0.484 0.498 0.534 0.514 0.494\n[469] 0.460 0.484 0.482 0.504 0.482 0.490 0.524 0.514 0.496 0.488 0.504 0.528\n[481] 0.502 0.474 0.502 0.524 0.522 0.520 0.480 0.510 0.476 0.522 0.502 0.484\n[493] 0.498 0.522 0.508 0.520 0.498 0.530 0.474 0.502\n"}︡{"file":{"filename":"/tmp/tmp7100fq.png","show":false,"text":null,"uuid":"9b6d0e65-ae6b-47f3-b01d-f2d9b50afc97"},"once":false}︡{"html":""}︡{"done":true}︡ ︠06bcbb96-e8c2-4e11-a5e6-f671982f3175s︠ %r # calc P(x>84) for normal distr'n mean 72 sd = 15.2 #pnorm(84, mean=72, sd=15.2, lower.tail=FALSE) # The length of a human pregnancy is normally distributed with a mean of 272 days # with a standard deviation of 9 days # find P(x>280) #pnorm(280, mean=272, sd=9, lower.tail = FALSE) data <- rnorm(500, mean=0, sd=1) # generate random data sampled from normal dist hist(data,freq = FALSE, col="red") #histogram the data x<-seq(-4,+4,by=0.02) #create sequence of x-vales around data mean for plotting curve(dnorm(x, mean=0, sd=1), add=TRUE, col="black", lwd=2) #plot data values. dnorm returns height at a given input value of the pdf ︡114d98d1-0808-4659-8894-556419c4315e︡{"file":{"filename":"/tmp/tmpNd6sJO.png","show":false,"text":null,"uuid":"1e86203c-dee1-44ea-90c0-2ee51d3473e8"},"once":false}︡{"html":""}︡{"done":true}︡