fit.plot: Plotting fitted and empirical distribution

Description Usage Arguments Value See Also Examples

Description

A function to plot empirical and fitted density (with given parameters) and compute differences between values of that densities.

Usage

1
2
3
fit.plot(x, densfun, param, distname = NULL, col = c("red"),col2 = c("grey"),col3 = c("blue"),
	 ylim = c(), xlim = c(), kernel = NULL, n = NULL, draw.diff = F, draw.max = F, 
	 scaled = F,positive=T, ...)

Arguments

x

a data vector

densfun

density function

param

density function parameters

distname

density function name ( optional)

col

fitted density colour (default red)

col2

draw.diff lines colour - see draw.max option

col3

draw.max line colour - see draw.max option

ylim

optional

xlim

optional

kernel

smoothing kernel to be used; see density

n

the number of equally spaced points at which the density is to be estimated; see density (if not given, default density n is used)

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 (x<- x/max(x)), then values computed and after that scaled once more; try it for dbeta distribution

positive

a logival value: compute differences only for positive x density arguments?

...

arguments passed to plot

Value

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

see also loss.fit.dist, fitdistr and plot.default

Examples

 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))

barryrowlingson/opVaR documentation built on May 11, 2019, 7:24 p.m.