Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/HistDist-03-10-13.R

This function fits constants to the parameters of a GAMLSS family distribution and them plot the histogram and the fitted distribution.

1 2 3 4 5 6 7 8 9 | ```
histDist(y, family = NO, freq = NULL, density = FALSE,
nbins = 10, xlim = NULL, ylim = NULL, main = NULL,
xlab = NULL, ylab = NULL, data = NULL,
col.hist = "gray", border.hist = "blue",
fg.hist = rainbow(12)[9], line.wd = 2,
line.ty = c(1, 2), line.col = c(2, 3),
col.main = "blue4", col.lab = "blue4",
col.axis = "blue", ...)
``` |

`y` |
a vector for the response variable |

`family` |
a |

`freq` |
the frequencies of the data in |

`density` |
default value is FALSE. Change to TRUE if you would like a non-parametric density plot together with the parametric fitted distribution plot (for continuous variable only) |

`nbins` |
The suggested number of bins (argument passed to |

`xlim` |
the minimum and the maximum x-axis value (if the default values are out of range) |

`ylim` |
the minimum and the maximum y-axis value (if the default values are out of range) |

`main` |
the main title for the plot |

`xlab` |
the label in the x-axis |

`ylab` |
the label in the y-axis |

`data` |
the data.frame |

`col.hist` |
the colour of the histogram or barplot |

`border.hist` |
the colour of the border of the histogram or barplot |

`fg.hist` |
the colour of axis in the histogram or barplot |

`line.wd` |
the line width of the fitted distribution |

`line.ty` |
the line type of the fitted distribution |

`line.col` |
the line color of the fitted distribution |

`col.main` |
the colour for the main title |

`col.lab` |
the colour of the labels |

`col.axis` |
the color of the axis |

`...` |
for extra arguments to be passed to the |

This function first fits constants for each parameters of a GAMLSS distribution family using the `gamlss`

function
and them plots the fitted distribution together with the appropriate plot according to whether
the `y`

variable is of a continuous or discrete type. Histogram is plotted for continuous and barplot for discrete variables.
The function `truehist`

of
Venables and Ripley's MASS package is used for the histogram plotting.

returns a plot

Mikis Stasinopoulos

Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion),
*Appl. Statist.*, **54**, part 3, pp 507-554.

Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019)
*Distributions for modeling location, scale, and shape: Using GAMLSS in R*, Chapman and Hall/CRC. An older version can be found in https://www.gamlss.com/.

Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R.
*Journal of Statistical Software*, Vol. **23**, Issue 7, Dec 2007, https://www.jstatsoft.org/v23/i07/.

Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017)
*Flexible Regression and Smoothing: Using GAMLSS in R*, Chapman and Hall/CRC.

(see also https://www.gamlss.com/).

1 2 3 4 5 6 7 8 9 10 11 12 13 | ```
data(abdom)
histDist(y,family="NO", data=abdom)
# use the ylim
histDist(y,family="NO", ylim=c(0,0.005), data=abdom)
# bad fit use PE
histDist(y,family="PE",ymax=0.005, data=abdom, line.col="blue")
# discere data counts
# Hand at al. p150 Leptinotarsa decemlineata
y <- c(0,1,2,3,4,6,7,8,10,11)
freq <- c(33,12,5,6,5,2,2,2,1,2)
histDist(y, "NBI", freq=freq)
# the same as
histDist(rep(y,freq), "NBI")
``` |

```
Loading required package: splines
Loading required package: gamlss.data
Loading required package: gamlss.dist
Loading required package: MASS
Loading required package: nlme
Loading required package: parallel
********** GAMLSS Version 5.0-2 **********
For more on GAMLSS look at http://www.gamlss.org/
Type gamlssNews() to see new features/changes/bug fixes.
Family: c("NO", "Normal")
Fitting method: "nlminb"
Call: gamlssML(formula = y, family = "NO", data = abdom)
Mu Coefficients:
[1] 226.7
Sigma Coefficients:
[1] 4.484
Degrees of Freedom for the fit: 2 Residual Deg. of Freedom 608
Global Deviance: 7201.42
AIC: 7205.42
SBC: 7214.24
Family: c("NO", "Normal")
Fitting method: "nlminb"
Call: gamlssML(formula = y, family = "NO", data = abdom)
Mu Coefficients:
[1] 226.7
Sigma Coefficients:
[1] 4.484
Degrees of Freedom for the fit: 2 Residual Deg. of Freedom 608
Global Deviance: 7201.42
AIC: 7205.42
SBC: 7214.24
Family: c("PE", "Power Exponential")
Fitting method: "nlminb"
Call: gamlssML(formula = y, family = "PE", data = abdom)
Mu Coefficients:
[1] 225.4
Sigma Coefficients:
[1] 4.494
Nu Coefficients:
[1] 2.325
Degrees of Freedom for the fit: 3 Residual Deg. of Freedom 607
Global Deviance: 7093
AIC: 7099
SBC: 7112.24
Family: c("NBI", "Negative Binomial type I")
Fitting method: "nlminb"
Call: gamlssML(formula = y, family = "NBI", weights = freq,
data = sys.parent())
Mu Coefficients:
[1] 0.6493
Sigma Coefficients:
[1] 0.7397
Degrees of Freedom for the fit: 2 Residual Deg. of Freedom 8
Global Deviance: 255.071
AIC: 259.071
SBC: 259.676
Family: c("NBI", "Negative Binomial type I")
Fitting method: "nlminb"
Call: gamlssML(formula = rep(y, freq), family = "NBI", data = sys.parent())
Mu Coefficients:
[1] 0.6493
Sigma Coefficients:
[1] 0.7397
Degrees of Freedom for the fit: 2 Residual Deg. of Freedom 68
Global Deviance: 255.071
AIC: 259.071
SBC: 263.568
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.