|
|
|
 | :: Exercise 1.13 - Free Statistics Software (Calculator) :: | |
|
All rights reserved. The non-commercial (academic) use of this software is free of charge. The only thing that is asked in return is to cite this software when results are used in publications.
This free online software (calculator) computes a solution for Exercise 1.13 p. 14 (Introduction to Probability, 2nd ed.)
Click here to edit the underlying code of this R Module.Click here to edit the underlying code of this R Module.
| Source code of R module | | 1 | par1 <- as.numeric(par1) | | 2 | par2 <- as.numeric(par2) | | 3 | par3 <- as.numeric(par3) | | 4 | par4 <- as.numeric(par4) | | 5 | numsuccessbig <- 0 | | 6 | numsuccesssmall <- 0 | | 7 | bighospital <- array(NA,dim=c(par1,par2)) | | 8 | smallhospital <- array(NA,dim=c(par1,par3)) | | 9 | bigprob <- array(NA,dim=par1) | | 10 | smallprob <- array(NA,dim=par1) | | 11 | for (i in 1:par1) { | | 12 | bighospital[i,] <- sample(c("F","M"),par2,replace=TRUE) | | 13 | if (as.matrix(table(bighospital[i,]))[2] > par4*par2) numsuccessbig = numsuccessbig + 1 | | 14 | bigprob[i] <- numsuccessbig/i | | 15 | smallhospital[i,] <- sample(c("F","M"),par3,replace=TRUE) | | 16 | if (as.matrix(table(smallhospital[i,]))[2] > par4*par3) numsuccesssmall = numsuccesssmall + 1 | | 17 | smallprob[i] <- numsuccesssmall/i | | 18 | } | | 19 | tbig <- as.matrix(table(bighospital)) | | 20 | tsmall <- as.matrix(table(smallhospital)) | | 21 | tbig | | 22 | tsmall | | 23 | numsuccessbig/par1 | | 24 | bigprob[par1] | | 25 | numsuccesssmall/par1 | | 26 | smallprob[par1] | | 27 | numsuccessbig/par1*365 | | 28 | bigprob[par1]*365 | | 29 | numsuccesssmall/par1*365 | | 30 | smallprob[par1]*365 | | 31 | bitmap(file="test1.png") | | 32 | plot(bigprob,col=2,main="Probability in Large Hospital",xlab="#simulated days",ylab="probability") | | 33 | dev.off() | | 34 | bitmap(file="test2.png") | | 35 | plot(smallprob,col=2,main="Probability in Small Hospital",xlab="#simulated days",ylab="probability") | | 36 | dev.off() | | 37 | load(file="createtable") | | 38 | a<-table.start() | | 39 | a<-table.row.start(a) | | 40 | a<-table.element(a,"Exercise 1.13 p. 14 (Introduction to Probability, 2nd ed.)",2,TRUE) | | 41 | a<-table.row.end(a) | | 42 | a<-table.row.start(a) | | 43 | a<-table.element(a,"Number of simulated days",header=TRUE) | | 44 | a<-table.element(a,par1) | | 45 | a<-table.row.end(a) | | 46 | a<-table.row.start(a) | | 47 | a<-table.element(a,"Expected number of births in Large Hospital",header=TRUE) | | 48 | a<-table.element(a,par2) | | 49 | a<-table.row.end(a) | | 50 | a<-table.row.start(a) | | 51 | a<-table.element(a,"Expected number of births in Small Hospital",header=TRUE) | | 52 | a<-table.element(a,par3) | | 53 | a<-table.row.end(a) | | 54 | a<-table.row.start(a) | | 55 | a<-table.element(a,"Percentage of Male births per day (for which the probability is computed)",header=TRUE) | | 56 | a<-table.element(a,par4) | | 57 | a<-table.row.end(a) | | 58 | a<-table.row.start(a) | | 59 | a<-table.element(a,"#Females births in Large Hospital",header=TRUE) | | 60 | a<-table.element(a,tbig[1]) | | 61 | a<-table.row.end(a) | | 62 | a<-table.row.start(a) | | 63 | a<-table.element(a,"#Males births in Large Hospital",header=TRUE) | | 64 | a<-table.element(a,tbig[2]) | | 65 | a<-table.row.end(a) | | 66 | a<-table.row.start(a) | | 67 | a<-table.element(a,"#Female births in Small Hospital",header=TRUE) | | 68 | a<-table.element(a,tsmall[1]) | | 69 | a<-table.row.end(a) | | 70 | a<-table.row.start(a) | | 71 | a<-table.element(a,"#Male births in Small Hospital",header=TRUE) | | 72 | a<-table.element(a,tsmall[2]) | | 73 | a<-table.row.end(a) | | 74 | a<-table.row.start(a) | | 75 | dum1 <- paste("Probability of more than", par4*100, sep=" ") | | 76 | dum <- paste(dum1, "Male births in Large Hospital", sep=" ") | | 77 | a<-table.element(a, dum, header=TRUE) | | 78 | a<-table.element(a, bigprob[par1]) | | 79 | a<-table.row.end(a) | | 80 | dum <- paste(dum1, "Male births in Small Hospital", sep=" ") | | 81 | a<-table.element(a, dum, header=TRUE) | | 82 | a<-table.element(a, smallprob[par1]) | | 83 | a<-table.row.end(a) | | 84 | a<-table.row.start(a) | | 85 | dum1 <- paste("#Days per Year when more than", par4*100, sep=" ") | | 86 | dum <- paste(dum1, "Male births occur in Large Hospital", sep=" ") | | 87 | a<-table.element(a, dum, header=TRUE) | | 88 | a<-table.element(a, bigprob[par1]*365) | | 89 | a<-table.row.end(a) | | 90 | dum <- paste(dum1, "Male births occur in Small Hospital", sep=" ") | | 91 | a<-table.element(a, dum, header=TRUE) | | 92 | a<-table.element(a, smallprob[par1]*365) | | 93 | a<-table.row.end(a) | | 94 | a<-table.end(a) | | 95 | table.save(a,file="mytable.tab") |
|
| Cite this software as: | | Wessa P., (2008), Excercise 1.13 of Introduction to Probability (v1.0.1) in Free Statistics Software (v1.1.23-r2), Office for Research Development and Education, URL http://www.wessa.net/rwasp_babies.wasp/ | | | The R code is based on : | | | Grinstead, Charles and Laurie Snell, Introduction to Probability, http://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/book.html | | | | | | | | | | | | | |
|
To cite Wessa.net in publications use: Wessa, P. (2008), Free Statistics Software, Office for Research Development and Education, version 1.1.23-r2, URL http://www.wessa.net/
© Resa
R&D, and the 'Office for Research, Development, and Education' - All rights reserved. Academic license for non-commercial use only.
This website is an intellectual
and physical property of Resa R&D. This includes: html content,
graphical illustrations (gif files), computer software, online or electronic
documentation, associated media, and printed materials. The free use of the scientific content, services, and applications in this website is
granted for non commercial use only. In any case,
the source (url) should always be clearly displayed. Under no circumstances are
you allowed to reproduce, copy or redistribute the design, layout, or any
content of this website (for commercial use) including any materials contained
herein without the express written permission of Resa R&D or the Office for Research, Development, and Education.
Information provided
on this web site is provided "AS IS" without warranty of any kind, either
express or implied, including, without limitation, warranties of
merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information
and periodically update the information, and software without notice. However, Resa
R&D makes no warranties or representations
as to the accuracy or completeness of such information (or software), and it assumes no
liability or responsibility for errors or omissions in the content of this web
site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and
under no legal theory shall Resa R&D be liable to you or any other
person for any direct, indirect, special, incidental, exemplary, or
consequential damages arising from your access to, or use of, this web site.
Software Version : 1.1.23-r2 Algorithms & Software : Prof. dr. P. Wessa Facilities : Resa R&D - Office for Research, Development, and Education Server : www.wessa.net
Comments, Feedback & Errors | Privacy Policy | Statistics Resources | Wessa.net Home
|
|
|
|
|
|
|
|