|
|
|
 | :: Random Number Generator - Log-Normal Distribution - 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) generates a specified number of random series for the Log-Normal distribution. The parameters allow you to specify the length of the dataseries to be generated, the mean of the distribution, and the standard error of the distribution.
The generated random numbers are listed in a table (if possible). In addition a histogram is shown of the estimated mean and standard deviation (over all simulated series)
This R module is an illustration of the central limit theorem.
Click here to edit the underlying code of this R Module.Click here to edit the underlying code of this R Module.
| Cite this software as: | | Wessa P., (2008), Random Number Generator for the Log-Normal Distribution (v1.0.4) in Free Statistics Software (v1.1.22-r6), Office for Research Development and Education, URL http://www.wessa.net/rwasp_rnglnorm.wasp/ | | | The R code is based on : | | | Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988), The New S Language, Wadsworth & Brooks/Cole. | | | | | | | | | | | | | |
|
| Source code of R module | | 1 | library(MASS) | | 2 | par1 <- as.numeric(par1) | | 3 | par2 <- as.numeric(par2) | | 4 | par2 <- round(par2,2) #rounded (we want to be able to display 10 columns) | | 5 | par3 <- as.numeric(par3) | | 6 | par3 <- round(par3,2) #rounded (we want to be able to display 10 columns) | | 7 | par4 <- as.numeric(par4) | | 8 | if (par6 == "0") par6 = "Sturges" else par6 <- as.numeric(par6) | | 9 | par7 <- as.numeric(par7) | | 10 | x <- array(NA,dim=c(par7,par1)) | | 11 | rest.mean <- array(NA,dim=c(par7)) | | 12 | rest.sd <- array(NA,dim=c(par7)) | | 13 | rsd.mean <- array(NA,dim=c(par7)) | | 14 | rsd.sd <- array(NA,dim=c(par7)) | | 15 | for (i in 1:par7) | | 16 | { | | 17 | x[i,] <- rlnorm(par1,par2,par3) | | 18 | x[i,] <- as.ts(x[i,]) #otherwise the fitdistr function does not work properly | | 19 | dum <- fitdistr(x[i,],"log-normal") | | 20 | rest.mean[i] <- dum$estimate[1] | | 21 | rest.sd[i] <- dum$estimate[2] | | 22 | rsd.mean[i] <- dum$sd[1] | | 23 | rsd.sd[i] <- dum$sd[2] | | 24 | } | | 25 | nc <- par7 | | 26 | if (nc > 10) nc = 10 | | 27 | if (par5 == "Y") | | 28 | { | | 29 | load(file="createtable") | | 30 | a<-table.start() | | 31 | a<-table.row.start(a) | | 32 | a<-table.element(a,"Index",1,TRUE) | | 33 | for (j in 1:nc) | | 34 | { | | 35 | a<-table.element(a,paste("X",j),1,TRUE) | | 36 | } | | 37 | a<-table.row.end(a) | | 38 | if (nc < par7) | | 39 | { | | 40 | a<-table.row.start(a) | | 41 | a<-table.element(a,"Note: only the first 10 series are displayed",nc+1,TRUE) | | 42 | a<-table.row.end(a) | | 43 | } | | 44 | for (i in 1:par1) | | 45 | { | | 46 | a<-table.row.start(a) | | 47 | a<-table.element(a,i,header=TRUE) | | 48 | for (j in 1:nc) | | 49 | { | | 50 | a<-table.element(a,round(x[j,i],2)) | | 51 | } | | 52 | a<-table.row.end(a) | | 53 | } | | 54 | a<-table.end(a) | | 55 | table.save(a,file="mytable1.tab") | | 56 | } | | 57 | load(file="createtable") | | 58 | a<-table.start() | | 59 | a<-table.row.start(a) | | 60 | a<-table.element(a,"Parameter",1,TRUE) | | 61 | for (j in 1:nc) | | 62 | { | | 63 | a<-table.element(a,paste("X",j,sep=""),1,TRUE) | | 64 | } | | 65 | a<-table.row.end(a) | | 66 | a<-table.row.start(a) | | 67 | a<-table.element(a," ",1,TRUE) | | 68 | for (j in 1:nc) | | 69 | { | | 70 | a<-table.element(a,"(SD)",1,TRUE) | | 71 | } | | 72 | a<-table.row.end(a) | | 73 | a<-table.row.start(a) | | 74 | a<-table.element(a,"# simulated values",header=TRUE) | | 75 | for (j in 1:nc) | | 76 | { | | 77 | a<-table.element(a,par1) | | 78 | } | | 79 | a<-table.row.end(a) | | 80 | a<-table.row.start(a) | | 81 | a<-table.element(a,"true mean",header=TRUE) | | 82 | for (j in 1:nc) | | 83 | { | | 84 | a<-table.element(a,par2) | | 85 | } | | 86 | a<-table.row.end(a) | | 87 | a<-table.row.start(a) | | 88 | a<-table.element(a,"true standard deviation",header=TRUE) | | 89 | for (j in 1:nc) | | 90 | { | | 91 | a<-table.element(a,par3) | | 92 | } | | 93 | a<-table.row.end(a) | | 94 | a<-table.row.start(a) | | 95 | a<-table.element(a,"mean",header=TRUE) | | 96 | for (j in 1:nc) | | 97 | { | | 98 | a<-table.element(a,round(rest.mean[j],2)) | | 99 | } | | 100 | a<-table.row.end(a) | | 101 | a<-table.row.start(a) | | 102 | a<-table.element(a," ",header=TRUE) | | 103 | for (j in 1:nc) | | 104 | { | | 105 | a<-table.element(a,round(rsd.mean[j],2)) | | 106 | } | | 107 | a<-table.row.end(a) | | 108 | a<-table.row.start(a) | | 109 | a<-table.element(a,"standard deviation",header=TRUE) | | 110 | for (j in 1:nc) | | 111 | { | | 112 | a<-table.element(a,round(rest.sd[j],2)) | | 113 | } | | 114 | a<-table.row.end(a) | | 115 | a<-table.row.start(a) | | 116 | a<-table.element(a," ",header=TRUE) | | 117 | for (j in 1:nc) | | 118 | { | | 119 | a<-table.element(a,round(rsd.sd[j],2)) | | 120 | } | | 121 | a<-table.row.end(a) | | 122 | a<-table.end(a) | | 123 | table.save(a,file="mytable.tab") | | 124 | bitmap(file="test0.png") | | 125 | myhist<-hist(x[1,],col=par4,breaks=par6,main="Histogram of 1st simulated series",ylab="density",xlab="simulated values",freq=F) | | 126 | dev.off() | | 127 | bitmap(file="test1.png") | | 128 | myhist<-hist(rest.mean[],col=par4,breaks=par6,main="Histogram of Estimated Means",ylab="density",xlab="estimated means",freq=F) | | 129 | x <- rest.mean[] | | 130 | dummean <- mean(x) | | 131 | dumsd <- sd(x) | | 132 | curve(1/(dumsd*sqrt(2*pi))*exp(-1/2*((x-dummean)/dumsd)^2),min(x),max(x),add=T) | | 133 | dev.off() | | 134 | bitmap(file="test2.png") | | 135 | myhist<-hist(rest.sd[],col=par4,breaks=par6,main="Histogram of Estimated SDs",ylab="density",xlab="estimated standard deviations",freq=F) | | 136 | x <- rest.sd[] | | 137 | dummean <- mean(x) | | 138 | dumsd <- sd(x) | | 139 | curve(1/(dumsd*sqrt(2*pi))*exp(-1/2*((x-dummean)/dumsd)^2),min(x),max(x),add=T) | | 140 | dev.off() |
|
To cite Wessa.net in publications use: Wessa, P. (2008), Free Statistics Software, Office for Research Development and Education, version 1.1.22-r6, 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.22-r6 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
|
|
|
|
|
|
|
|