Learn R Programming

piecenorms (version 1.1.0)

normalisr: Creates a recommended classInt based on the type of distribution.

Description

Creates a recommended classInt based on the type of distribution.

Creates a recommended classInt based on the type of distribution.

Arguments

Public fields

data

(numeric())
Original observations

outliers

(logical())
Logical vector indicating is observations are outliers

quantiles

(numeric())
Vector of quantiles

fitted_distribution

(character())
Suggested distribution

normalisation

(character())
Recommended class interval style based on distribution

breaks

(numeric())
Recommended breaks for classes

number_of_classes

(numeric())
Number of classes identified

normalised_data

(numeric())
Normalised values based on recommendations

polarity

(numeric(1))
Which direction should the normalisation occur

percentiles

(numeric())
Observation percentiles

fittedmodel

(character())
Fitted univariate model

model

(univariateML())
Fitted univariate model parameters

Methods


Method new()

Creates a new instance of this R6 class.

Create a new normalisr object.

Usage

normalisr$new(
  x,
  polarity = 1,
  classint_preference = "jenks",
  num_classes = NULL,
  potential_distrs = c("unif", "power", "norm", "lnorm", "weibull", "pareto", "exp")
)

Arguments

x

A numeric vector of observations

polarity

Which direction should the normalisation occur, defaults to 1 but can either be:

  • 1:: Lowest value is normalised to 0, highest value is normalised to 1

  • -1: Highest value is normalised to 0, lowest value is normalised to 1

classint_preference

Preference for classInt breaks (see ?classInt::classIntervals)

num_classes

Preference for number of classInt breaks, defaults to Sturges number (see
?grDevices::nclass.Sturges)

potential_distrs

The types of distributions to fit, defaults to c("unif", "power", "norm", "lnorm", "weibull", "pareto", "exp")

Returns

A new normalisr object.


Method print()

Prints the normalisr

Usage

normalisr$print()


Method plot()

Plots the normalised values against the original

Usage

normalisr$plot()


Method hist()

Histogram of normalised values against the original

Usage

normalisr$hist()


Method setManualBreaks()

Allows user to set manual breaks

Usage

normalisr$setManualBreaks(brks)

Arguments

brks

User Defined Breaks


Method applyto()

Applies the normalisation model to new data

Usage

normalisr$applyto(x)

Arguments

x

A numeric vector of observations


Method as.data.frame()

Returns a data frame of the normalisation

Usage

normalisr$as.data.frame()


Method clone()

The objects of this class are cloneable with this method.

Usage

normalisr$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Creates a normalisr R6 class for recommending a classInt based on the shape of the distribution of the observed data

Examples

Run this code
set.seed(12345)

# Binary distribution test
x <- sample(c(0,1), 100, replace = TRUE)
y <- sample(c(0,1), 100, replace = TRUE)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Uniform distribution test
x <- runif(100)
y <- runif(100)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)


# Normal distribution tests
x <- rnorm(100)
y <- rnorm(100)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Lognormal distribution tests
x <- rlnorm(100)
y <- rlnorm(100)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Lognormal distribution tests with 5 classes
x <- rlnorm(100)
y <- rlnorm(100)
mdl <- normalisr$new(x, num_classes = 5)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Exponential distribution test
x <- exp(1:100)
y <- exp(1:100)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Poisson distribution test
x <- rpois(100, lambda = 0.5)
y <- rpois(100, lambda = 0.5)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Weibull distribution test
x <- rweibull(100, shape = 0.5)
y <- rweibull(100, shape = 0.5)
mdl <- normalisr$new(x)
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

# Set user defined breaks
mdl$setManualBreaks(c(5,10))
print(mdl)
mdl$plot()
mdl$hist()
head(mdl$as.data.frame())
mdl$applyto(y)

Run the code above in your browser using DataLab