Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Merge branch 'main' of https://github.com/gamlss-dev/gamlss2

# Conflicts:
#	vignettes/families.Rmd
  • Loading branch information
mstasinopoulos committed Oct 2, 2024
2 parents 1d51a91 + 70eed62 commit 75b3179
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 55 deletions.
8 changes: 3 additions & 5 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ inst/tests.qmd
inst/SGT.R
inst/OpenTopics.qmd
token
random.Rmd
selection.Rmd
spatial.Rmd
s_pb.Rmd
topmodels.Rmd
README.qmd
.github
^_quarto$
^altdoc$
^docs$
^.*\.Rproj$
^\.Rproj\.user$
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
.Rhistory
.Rapp.history
.Rproj.user/

# vignette output
vignettes/*.html
vignettes/*.pdf

# altdoc infrastructure
altdoc/freeze.rds
_quarto/
docs/
.Rbuildignore
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ URL: https://gamlss-dev.github.io/gamlss2/
BugReports: https://github.com/gamlss-dev/gamlss2/issues
Depends: R (>= 4.1.0), gamlss.dist, mgcv
Imports: parallel, Formula, mvtnorm
Suggests: gamlss, gamlss.data, colorspace, knitr, scoringRules, partykit, Matrix, nnet, lattice, rpart, distributions3, nlme
Suggests: gamlss, gamlss.data, colorspace, ggplot2, knitr, scoringRules, partykit, Matrix, nnet, lattice, rpart, distributions3, nlme, sf, spdep
LazyLoad: yes
VignetteBuilder: knitr

3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export(
"new_formula",
"softplus",
"shiftlog",
"Kumaraswamy"
"Kumaraswamy",
"make.link2"
)

S3method(gamlss2, formula)
Expand Down
10 changes: 10 additions & 0 deletions R/specials.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ special_terms <- function(x, data, binning = FALSE, digits = Inf, ...)
}
}

if(any(dups <- duplicated(names(sterms)))) {
dups <- names(sterms)[dups]
for(j in dups) {
dn <- grep(j, names(sterms), fixed = TRUE, value = TRUE)
dn <- paste0(dn, ".", 1:length(dn))
i <- grep(j, names(sterms), fixed = TRUE)
names(sterms)[i] <- dn
}
}

return(sterms)
}

Expand Down
56 changes: 24 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@


# gamlss2: Infrastructure for Distributional Regression
# gamlss2: GAMLSS Infrastructure for Flexible Distributional Regression

## Installation

The development version of *gamlss2* can be installed via
The development version of _gamlss2_ can be installed via

``` r
```{r installation, eval = FALSE}
install.packages("gamlss2",
repos = c("https://gamlss-dev.R-universe.dev", "https://cloud.R-project.org"))
```

## Overview

The primary purpose of this package is to facilitate the creation of
advanced infrastructures designed to enhance the GAMLSS modeling
framework. Notably, the *gamlss2* package represents a significant
overhaul of its predecessor, *gamlss*, with a key emphasis on improving
estimation speed and incorporating more flexible infrastructures. These
enhancements enable the seamless integration of various algorithms into
GAMLSS, including gradient boosting, Bayesian estimation, regression
trees, and forests, fostering a more versatile and powerful modeling
environment.

Moreover, the package expands its compatibility by supporting all model
terms from the base R *mgcv* package. Additionally, the *gamlss2*
package introduces the capability to accommodate more than four
parameter families. Essentially, this means that users can now specify
any type of model using these new infrastructures, making the package
highly flexible and accommodating to a wide range of modeling
requirements.

- The main model function is `gamlss2()`.
- The default optimizer functions is `RS()`. Optimizer functions can
be exchanged.
- Most important methods: `summary()`, `plot()`, `predict()`.
- Easy development of new family objects, see `?family.gamlss2`.
- User-specific “special” terms are possible, see `?special_terms`.
## Overview

The primary purpose of this package is to facilitate the creation of advanced infrastructures
designed to enhance the GAMLSS modeling framework. Notably, the _gamlss2_ package represents a
significant overhaul of its predecessor, _gamlss_, with a key emphasis on improving estimation
speed and incorporating more flexible infrastructures. These enhancements enable the seamless
integration of various algorithms into GAMLSS, including gradient boosting, Bayesian estimation,
regression trees, and forests, fostering a more versatile and powerful modeling environment.

Moreover, the package expands its compatibility by supporting all model terms from the base
R _mgcv_ package. Additionally, the _gamlss2_ package introduces the capability to
accommodate more than four parameter families. Essentially, this means that users can now
specify any type of model using these new infrastructures, making the package highly
flexible and accommodating to a wide range of modeling requirements.

* The main model function is `gamlss2()`.
* The default optimizer functions is `RS()`. Optimizer functions can be exchanged.
* Most important methods: `summary()`, `plot()`, `predict()`.
* Easy development of new family objects, see `?family.gamlss2`.
* User-specific "special" terms are possible, see `?special_terms`.

For examples, please visit the manual pages.

``` r
```{r help, eval = FALSE}
help(package = "gamlss2")
```
Binary file added data/Germany.rda
Binary file not shown.
Binary file added data/storms.rda
Binary file not shown.
27 changes: 27 additions & 0 deletions inst/extra/GermanyElevation.grd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[general]
creator=R package 'raster'
created=2024-09-30 08:52:19
[data]
datatype=FLT4S
byteorder=little
nbands=1
bandorder=BIL
categorical=FALSE
minvalue=-33
maxvalue=1992
nodatavalue=-3.4e+38
[legend]
legendtype=
values=
color=
[description]
layername=file29ba723b9492a
[georeference]
nrows=209
ncols=246
xmin=5.87622623088577
ymin=47.2597641144092
xmax=15.0252873245434
ymax=55.0327469134923
projection=+proj=longlat +datum=WGS84 +no_defs
wkt=GEOGCRS["unknown", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]], ID["EPSG",6326]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]], CS[ellipsoidal,2], AXIS["longitude",east, ORDER[1], ANGLEUNIT["degree",0.0174532925199433, ID["EPSG",9122]]], AXIS["latitude",north, ORDER[2], ANGLEUNIT["degree",0.0174532925199433, ID["EPSG",9122]]]]
Binary file added inst/extra/GermanyElevation.gri
Binary file not shown.
47 changes: 47 additions & 0 deletions man/Germany.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
\name{Germany}
\alias{Germany}

\encoding{UTF-8}

\title{Map of Germany}

\description{
The map contains the counties of Germany. The data was originally taken from
GADM (\url{https://gadm.org/}) and slightly simplified to reduce disk space.
}

\usage{data("storms", package = "gamlss2")}

\format{
A class \code{"sf"} data frame containing 403 counties of Germany.
\describe{
\item{id}{Factor, a county id.}
\item{county}{Character, the county in Germany where the weather station is located.}
\item{state}{Character, the state in Germany where the weather station is located.}
\item{geometry}{The polygon information.}
}
}

\source{
Map of Germany:
\describe{
\item{Data Source:}{GADM}
\item{Licence:}{CC BY}
\item{URL:}{\url{https://gadm.org/}}
\item{Coordinate Reference System:}{Longitude/latitude and the WGS84 datum.}
}
}

\examples{\dontshow{ if(!requireNamespace("sf")) { if(interactive() || is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA))) { stop("not all packages required for the example are installed") } else q() }}
## load sf package for plotting
library("sf")

## load the data
data("Germany", package = "gamlss2")

## plot the map
plot(st_geometry(Germany))
}

\keyword{datasets}

44 changes: 44 additions & 0 deletions man/make.link2.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
\name{make.link2}
\alias{make.link2}

\title{Create a Link for Families}

\description{
This function is used with the \code{family} functions in \code{gamlss2()}.
Given the name of a link, it returns a link function, an inverse
link function, the derivative \eqn{d\mu/d\eta}, and a function for domain
checking. Note that \code{make.link2()} is slightly more flexible and also allows
functions as arguments.
}

\usage{
make.link2(link)
}

\arguments{
\item{link}{
A character string, see function \code{\link[stats]{make.link}}, or function.
}
}

\value{
A list containing the following components:
\item{linkfun}{Link function \code{function(mu)}.}
\item{linkinv}{Inverse link function \code{function(eta)}.}
\item{mu.eta}{Derivative \code{function(eta)}: \eqn{d\mu/d\eta}.}
\item{valideta}{Function \code{function(eta)} that returns \code{TRUE} if \code{eta} is in the domain of \code{linkinv}.}
\item{name}{A character string representing the name of the link function.}
}

\seealso{
\code{\link[stats]{make.link}}, \code{\link{gamlss2}}, \code{\link{gamlss2.family}}.
}

\examples{
## character specification
utils::str(make.link2("logit"))

## functions
utils::str(make.link2(softplus))
}

66 changes: 66 additions & 0 deletions man/storms.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
\name{storms}
\alias{storms}

\encoding{UTF-8}

\title{Severe Storms in Germany}

\description{
According to the Beaufort scale, severe storms occur from a wind speed of 24.5-28.4 m/s.
This dataset contains annual severe storm counts from weather stations in Germany
from 1981 to 2021.
}

\usage{data("storms", package = "gamlss2")}

\format{
A data frame containing 3494 observations on 8 variables.
\describe{
\item{id}{Factor, the weather station id.}
\item{county}{Character, the county in Germany where the weather station is located.}
\item{state}{Character, the state in Germany where the weather station is located.}
\item{year}{Integer, the year the observation was measured.}
\item{counts}{Integer, the number of severe storms in this year.}
\item{alt}{Numeric, the altitude in meters above sea level of the weather station.}
\item{lon}{Numeric, the longitude coordinate of the weather station.}
\item{lat}{Numeric, the latitude coordinate of the weather station.}
}
}

\source{
Severe Storms Data:
\describe{
\item{Data Source:}{Deutscher Wetterdienst (DWD), Climate Data Center (CDC).}
\item{Licence:}{CC BY 4.0}
\item{URL:}{\url{https://opendata.dwd.de/climate_environment/CDC/}}
\item{Coordinate Reference System:}{Longitude/latitude and the WGS84 datum.}
}
}

\examples{
## load the data
data("storms", package = "gamlss2")

## yearly observations
plot(counts ~ year, data = storms)

## count distribution
barplot(table(storms$counts))

## NBI model
## model formula including spatial effect
\dontrun{f <- counts ~ s(year) + s(alt) + s(lon, lat) |
s(year) + s(alt) + s(lon, lat)

## estimate model
b <- gamlss2(f, data = storms, family = NBI)

## estimated effects
plot(b)

## residual diagnostics
plot(b, which = "resid")
}}

\keyword{datasets}

Loading

0 comments on commit 75b3179

Please sign in to comment.