Description Usage Arguments Value See Also Examples
A function to plot empirical and fitted density (with given parameters) and compute differences between values of that densities.
1 2 3 |
x |
a data vector |
densfun |
density function |
param |
density function parameters |
distname |
density function name ( |
col |
fitted density colour (default |
col2 |
draw.diff lines colour - see draw.max option |
col3 |
draw.max line colour - see draw.max option |
ylim |
|
xlim |
|
kernel |
smoothing kernel to be used; see |
n |
the number of equally spaced points at which the density is to be estimated; see |
draw.diff |
logical; draw differences between empirical and estimated density values? |
draw.max |
logical; draw maximal differences between empirical and estimated density values? |
scaled |
a logical value. If TRUE, values are scaled ( |
positive |
a logival value: compute differences only for positive x density arguments? |
... |
arguments passed to |
ad |
absolute differences between empirical and fitted density values |
teor |
fitted density values |
emp |
empirical density values |
maxdiff |
maximum difference between empirical and fitted density values |
meandiff |
mean difference between empirical and fitted density values |
see also loss.fit.dist
, fitdistr
and plot.default
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 | # first example:
data(loss.data.object) # data reading
x<- read.loss(1,2,loss.data.object) # choice of data
z<- x[,2] # z is loss data
fit.plot(z,dnorm, param = list(mean = mean(z),sd = sd(z)))
# and the same with draw.diff = T
fit.plot(z,dnorm, param = list(mean = mean(z),sd = sd(z)),draw.diff=T)
# draw.diff = T, draw.max = T (maximum difference is drawn),
# n = 40 (density values are computed only for 40 points)
fit1<-fit.plot(z,dnorm, param = list(mean = mean(z),sd = sd(z)),draw.diff=T,n=40)
length(fit1$teor) # absolute differences are computed only for positive density arguments
length(fit1$emp) # number of arguments
# then ad is computed as sum of that absolute differences
# compare:
sum(abs(fit1$teor - fit1$emp))
fit1$ad
# compare:
par(mfrow = c(2,1))
fit.plot(z,dnorm, param = list(mean = mean(z),sd = sd(z)),draw.diff=T,n=40,col2 = "darkblue")
fit.plot(z,dnorm, param = list(mean = mean(z),sd = sd(z)),draw.diff=T,n=40,positive=F,col2 = "darkblue")
# more values thanks to positive = F
# second example:
# beta distribution is special because it is scaled
fit.plot(z,dbeta,"beta", param = list(shape1 = 0.4,shape2=17))
# ... and with x logarithmic scale
fit.plot(z,dbeta,"beta", param = list(shape1 = 0.4,shape2=17),log = "x")
# third example:
parameters <-loss.fit.dist("lognormal",x)$param # fits lognormal distribution to
# second column of our data (i.e. z)
parameters <- as.numeric(parameters)
parameters # the estimated parameters of lognormal distribution
fit.plot(z,dlnorm,distname = "lognormal",
param = list(meanlog = parameters[1],sdlog = parameters[2]))
# ... and with x logarithmic scale
fit.plot(z,dlnorm,distname = "lognormal",
param = list(meanlog = parameters[1],sdlog = parameters[2]),log="x")
# lognormal seems to fit that data
# and with differences drawn (there was ylim changed to see these lines better)
fit.plot(z,dlnorm,distname = "lognormal",
param = list(meanlog = parameters[1],sdlog = parameters[2]),log="x",draw.diff=T,ylim = c(0,4e-05))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.