Title: | Demos for GAMLSS |
---|---|
Description: | Demos for smoothing and gamlss.family distributions. |
Authors: | Mikis Stasinopoulos <[email protected]>, Bob Rigby <[email protected]>, Paul Eilers <[email protected]>, Brian Marx \email{[email protected]}, Konstantinos Pateras <[email protected]> with contributions from Larisa Kosidou. |
Maintainer: | Mikis Stasinopoulos <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 4.3-3 |
Built: | 2024-11-04 06:37:05 UTC |
Source: | CRAN |
These are demos for teaching smoothing techniques to students
demo.BSplines() demo.RandomWalk(y = NULL, ...) demo.histSmo(y = NULL, ...) demo.interpolateSmo(y = NULL, w = NULL, ...) demo.PSplines(y = NULL, x = NULL, ...)
demo.BSplines() demo.RandomWalk(y = NULL, ...) demo.histSmo(y = NULL, ...) demo.interpolateSmo(y = NULL, w = NULL, ...) demo.PSplines(y = NULL, x = NULL, ...)
y |
for y variable if needed otherwise it is generated |
w |
for weights if needed |
x |
for explanatory variable if needed |
... |
for adding parameters in the plot |
An rpanel plot
Paul Eirers [email protected], Brian Marx [email protected], and Mikis Stasinopoulos [email protected]
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
Eilers, P. H. C. and Marx, B. D. (1996). Flexible smoothing with B-splines and penalties (with comments and rejoinder). Statist. Sci, 11, 89-121.
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
demo.PSplines()
demo.PSplines()
This function demonstrate some characteristics of local regression Smoothing
demo.LocalRegression(y = NULL, x = NULL, span = 0.5, position = trunc((n - 1)/2), deg = 1) LPOL(y, x, span = 0.5, position = trunc((n - 1)/2), w = rep(1, length(y)), deg = 1) WLPOL(y, x, sd = 0.5, position = trunc((n - 1)/2), w = rep(1, length(y)), deg = 1)
demo.LocalRegression(y = NULL, x = NULL, span = 0.5, position = trunc((n - 1)/2), deg = 1) LPOL(y, x, span = 0.5, position = trunc((n - 1)/2), w = rep(1, length(y)), deg = 1) WLPOL(y, x, sd = 0.5, position = trunc((n - 1)/2), w = rep(1, length(y)), deg = 1)
y |
The response variable |
x |
the explanatory variable |
span |
The smoothing parameters |
sd |
The standard deviation of a normal kernel used as smoothing parameter |
position |
The position of the target values in the x axis |
w |
weights |
deg |
The degree of the local polynomial |
The function demo.LocalRegression
demonstrates some aspects of the Local (unweighed) polynomial regression. The functions LPOL()
and WLPOL()
produce plots related to unweighed and weighted local polynomial regression respectively.
All function produce plots.
Mikis Stasinopoulos
R Development Core Team (2010) tcltk package, CRAN.
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
See also demoDist
, gamlss.demo
demo.LocalRegression() n <- 100 x <- seq(0, 1, length = n)*1.4 y <- 1.2 + .3*sin(5 * x) + rnorm(n) * 0.2 op <- par(mfrow=c(2,2)) LPOL(y,x, deg=0, position=5) title("(a) moving average") LPOL(y,x, deg=1, position=75) title("(b) linear poly") WLPOL(y,x, deg=2, position=30) title("(c) quadratic poly") WLPOL(y,x, deg=3, position= 50) title("(b) cubic poly") par(op)
demo.LocalRegression() n <- 100 x <- seq(0, 1, length = n)*1.4 y <- 1.2 + .3*sin(5 * x) + rnorm(n) * 0.2 op <- par(mfrow=c(2,2)) LPOL(y,x, deg=0, position=5) title("(a) moving average") LPOL(y,x, deg=1, position=75) title("(b) linear poly") WLPOL(y,x, deg=2, position=30) title("(c) quadratic poly") WLPOL(y,x, deg=3, position= 50) title("(b) cubic poly") par(op)
Those are four demos to show weighed and unweighed local mean and polynomial smoothing.
demo.Locmean(y = NULL, x = NULL, ...) demo.Locpoly(y = NULL, x = NULL, ...) demo.WLocpoly(y = NULL, x = NULL, ...) demo.WLocmean(y = NULL, x = NULL, ...)
demo.Locmean(y = NULL, x = NULL, ...) demo.Locpoly(y = NULL, x = NULL, ...) demo.WLocpoly(y = NULL, x = NULL, ...) demo.WLocmean(y = NULL, x = NULL, ...)
y |
the response variable. If null it generates its own data |
x |
explanatory variable |
... |
for extra argument in the plot |
It produces an rpanel plot
Mikis Stasinopoulos [email protected]
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
Eilers, P. H. C. and Marx, B. D. (1996). Flexible smoothing with B-splines and penalties (with comments and rejoinder). Statist. Sci, 11, 89-121.
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
demo.Locmean()
demo.Locmean()
The demo functions for showning the gamlss.family
distributions. The functions use the package Rpanel
.
demo.NO() demo.LO() demo.NO.LO() demo.GU() demo.RG() demo.exGAUS() demo.PE() demo.PE.NO() demo.TF() demo.TF.NO() demo.EGB2() demo.GT() demo.JSU() demo.JSUo() demo.NET() demo.SHASH() demo.SEP1() demo.SEP2() demo.SEP3() demo.SEP4() demo.ST1() demo.ST2() demo.ST3() demo.ST4() demo.ST5() demo.EXP() demo.GA() demo.LOGNO() demo.NO.LOGNO() demo.IG() demo.WEI() demo.WEI2() demo.WEI3() demo.BCCG() demo.GG() demo.GIG() demo.ZAGA() demo.ZAIG() demo.BCT() demo.BCPE() demo.GB2() demo.EGB2() demo.BE() demo.BEo() demo.GB1() demo.GT() demo.BB() demo.BEINF() demo.BEINF0() demo.BEINF1() demo.BI() demo.DEL() demo.LG() demo.NBI() demo.NBII() demo.PO() demo.SICHEL() demo.ZABI() demo.ZAGA() demo.ZALG() demo.ZAP() demo.ZIBI() demo.ZIP() demo.ZIP2() demo.BCCG() demo.GG() demo.PIG() demo.ZABB() demo.ZIBB() demo.ZANBI() demo.ZINBI() demo.ZIPIG() demo.NOtr() demo.GAtr() demo.YULE() demo.WARING() demo.GEOM() demo.IGAMMA() demo.PARETO2() demo.PARETO2o() demo.SHASHo() demo.SHASHo2() demo.LOGITNO() demo.LOGNO2() demo.SN1() demo.SN2() demo.SST() demo.TF2() demo.DPO()
demo.NO() demo.LO() demo.NO.LO() demo.GU() demo.RG() demo.exGAUS() demo.PE() demo.PE.NO() demo.TF() demo.TF.NO() demo.EGB2() demo.GT() demo.JSU() demo.JSUo() demo.NET() demo.SHASH() demo.SEP1() demo.SEP2() demo.SEP3() demo.SEP4() demo.ST1() demo.ST2() demo.ST3() demo.ST4() demo.ST5() demo.EXP() demo.GA() demo.LOGNO() demo.NO.LOGNO() demo.IG() demo.WEI() demo.WEI2() demo.WEI3() demo.BCCG() demo.GG() demo.GIG() demo.ZAGA() demo.ZAIG() demo.BCT() demo.BCPE() demo.GB2() demo.EGB2() demo.BE() demo.BEo() demo.GB1() demo.GT() demo.BB() demo.BEINF() demo.BEINF0() demo.BEINF1() demo.BI() demo.DEL() demo.LG() demo.NBI() demo.NBII() demo.PO() demo.SICHEL() demo.ZABI() demo.ZAGA() demo.ZALG() demo.ZAP() demo.ZIBI() demo.ZIP() demo.ZIP2() demo.BCCG() demo.GG() demo.PIG() demo.ZABB() demo.ZIBB() demo.ZANBI() demo.ZINBI() demo.ZIPIG() demo.NOtr() demo.GAtr() demo.YULE() demo.WARING() demo.GEOM() demo.IGAMMA() demo.PARETO2() demo.PARETO2o() demo.SHASHo() demo.SHASHo2() demo.LOGITNO() demo.LOGNO2() demo.SN1() demo.SN2() demo.SST() demo.TF2() demo.DPO()
An rpanel plot
Mikis Stasinopoulos [email protected], Bob Rigby [email protected] with contribution from Larisa Kosidou.
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
demo.NO()
demo.NO()
The function demoDist
is an tcltk
interface for plotting all the available
gamlss.family
distributions.
demoDist()
demoDist()
It creates a tcltk
menu
Konstantinos Pateras [email protected]
R Development Core Team (2010) tcltk package, CRAN.
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
## do not run demoDist()
## do not run demoDist()
It starts the gamlss local plynomial demos demos. It is an tcltk
interface for using the local polynolial demos.
demoLpolyS()
demoLpolyS()
It creates a tcltk
menu
Konstantinos Pateras [email protected]
R Development Core Team (2010) tcltk package, CRAN.
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
See also demoDist
, gamlss.demo
,
demoLpolyS()
demoLpolyS()
The function demoPsplines
is an tcltk
interface for P. Eilers and B. Marx demos for P-splines.
demoPsplines()
demoPsplines()
Create an tcltk
menu
Konstantinos Pateras [email protected]
R Development Core Team (2010) tcltk package, CRAN.
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
See also demoDist
, ~~~
demoPsplines()
demoPsplines()
It starts the gamlss demos. It is an tcltk
interface for using the gamlss demos.
gamlss.demo()
gamlss.demo()
It creates a tcltk
menu
Konstantinos Pateras [email protected]
R Development Core Team (2010) tcltk package, CRAN.
Bowman, Bowman, Gibson and Crawford (2008) rpanel, CRAN
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/i07.
See also demoDist
, gamlss.demo
,
gamlss.demo()
gamlss.demo()
There are four function here to illustrate the fitting of local regressions.
i) Locmean
, which uses local means within a symmetric local window,
ii) Locpoly
, which uses a local polynomial fit within a symmetric local window.
iii) WLocmean
, which uses a Gaussian kernel and
iv) WLocpoly
, which uses local polynomials weighted by a Gaussian kernel
Locmean(y, x = seq(1, length(y)), w = rep(1, length(y)), span = 0.5) Locpoly(y, x = seq(1, length(y)), w = rep(1, length(y)), span = 0.5, order = 1) WLocmean(y, x = seq(1, length(y)), w = rep(1, length(y)), lambda = 0.5) WLocpoly(y, x = seq(1, length(y)), w = rep(1, length(y)), lambda = 0.5, order = 1)
Locmean(y, x = seq(1, length(y)), w = rep(1, length(y)), span = 0.5) Locpoly(y, x = seq(1, length(y)), w = rep(1, length(y)), span = 0.5, order = 1) WLocmean(y, x = seq(1, length(y)), w = rep(1, length(y)), lambda = 0.5) WLocpoly(y, x = seq(1, length(y)), w = rep(1, length(y)), lambda = 0.5, order = 1)
y |
the response variable |
x |
the x-variable |
w |
prior weights |
span |
the side of the local window compare as a proportion to the total number of observations |
lambda |
the smoothing parameter for the Gaussian kernel |
order |
the order of the polynomial |
Those functions can be used for illustration of the basic concepts of smoothing using small data sets. Do not use them with large data because are computationally inefficient.
The functions return a locW
object with values
fitted.values |
the fitted valus |
residuals |
the residuals |
edf |
the effective degrees of freedom |
rss |
the residual sum of squares |
lambda |
the smoothing parameter |
y |
the y variable |
x |
the x variable |
w |
the prior weights |
Mikis Stasinopoulos, [email protected]
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/)
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, http://www.jstatsoft.org/v23/i07.
library(MASS) data(mcycle) # local means m0<-Locmean(mcycle$accel, mcycle$times, span=.1) m1<-Locmean(mcycle$accel, mcycle$times, span=.2) m2<-Locmean(mcycle$accel, mcycle$times, span=.3) span <- c("span=0.1", "span=0.2", "span=0.3") plot(accel~times, data=mcycle,main="local mean") lines(fitted(m0)~mcycle$times, col=1, lty=1) lines(fitted(m1)~mcycle$times, col=2, lty=2) lines(fitted(m2)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = span, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1) # kernel estimation k0<-WLocmean(mcycle$accel, mcycle$times, lambda=1) k1<-WLocmean(mcycle$accel, mcycle$times, lambda=2) k2<-WLocmean(mcycle$accel, mcycle$times, lambda=3) lambda <- c("lambda=1", "lambda=2", "lambda=3") plot(accel~times, data=mcycle,main="Gaussian kernel fit") lines(fitted(k0)~mcycle$times, col=1, lty=1) lines(fitted(k1)~mcycle$times, col=2, lty=2) lines(fitted(k2)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = lambda, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1) # local polymials l1<-Locpoly(mcycle$accel, mcycle$times, span=.1) l2<-Locpoly(mcycle$accel, mcycle$times, span=.2) l3<-Locpoly(mcycle$accel, mcycle$times, span=.3) span <- c("span=0.1", "span=0.2", "span=0.3") plot(accel~times, data=mcycle,main="local linear fit") lines(fitted(l1)~mcycle$times, col=1, lty=1) lines(fitted(l2)~mcycle$times, col=2, lty=2) lines(fitted(l2)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = span, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1) # weighted local polynomials lw1<-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=1) lw2<-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=2) lw3<-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=3) span <- c("linear", "quadratic", "cubic") plot(accel~times, data=mcycle,main="Weighted local linear, quadratic and cubic fits") lines(fitted(lw1)~mcycle$times, col=1, lty=1) lines(fitted(lw2)~mcycle$times, col=2, lty=2) lines(fitted(lw3)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = span, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1)
library(MASS) data(mcycle) # local means m0<-Locmean(mcycle$accel, mcycle$times, span=.1) m1<-Locmean(mcycle$accel, mcycle$times, span=.2) m2<-Locmean(mcycle$accel, mcycle$times, span=.3) span <- c("span=0.1", "span=0.2", "span=0.3") plot(accel~times, data=mcycle,main="local mean") lines(fitted(m0)~mcycle$times, col=1, lty=1) lines(fitted(m1)~mcycle$times, col=2, lty=2) lines(fitted(m2)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = span, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1) # kernel estimation k0<-WLocmean(mcycle$accel, mcycle$times, lambda=1) k1<-WLocmean(mcycle$accel, mcycle$times, lambda=2) k2<-WLocmean(mcycle$accel, mcycle$times, lambda=3) lambda <- c("lambda=1", "lambda=2", "lambda=3") plot(accel~times, data=mcycle,main="Gaussian kernel fit") lines(fitted(k0)~mcycle$times, col=1, lty=1) lines(fitted(k1)~mcycle$times, col=2, lty=2) lines(fitted(k2)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = lambda, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1) # local polymials l1<-Locpoly(mcycle$accel, mcycle$times, span=.1) l2<-Locpoly(mcycle$accel, mcycle$times, span=.2) l3<-Locpoly(mcycle$accel, mcycle$times, span=.3) span <- c("span=0.1", "span=0.2", "span=0.3") plot(accel~times, data=mcycle,main="local linear fit") lines(fitted(l1)~mcycle$times, col=1, lty=1) lines(fitted(l2)~mcycle$times, col=2, lty=2) lines(fitted(l2)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = span, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1) # weighted local polynomials lw1<-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=1) lw2<-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=2) lw3<-WLocpoly(mcycle$accel, mcycle$times, lambda=1.5, order=3) span <- c("linear", "quadratic", "cubic") plot(accel~times, data=mcycle,main="Weighted local linear, quadratic and cubic fits") lines(fitted(lw1)~mcycle$times, col=1, lty=1) lines(fitted(lw2)~mcycle$times, col=2, lty=2) lines(fitted(lw3)~mcycle$times, col=3, lty=3) legend(1.5,50, legend = span, col = 1:3, lty = 1:3, cex = .8, y.intersp = 1)