Skip to content

Commit

Permalink
Merge pull request #3 from Kimitsuna-Goblin/develop
Browse files Browse the repository at this point in the history
close #2
  • Loading branch information
Kimitsuna-Goblin authored Jan 8, 2024
2 parents d593e49 + 2395ba7 commit 24b5146
Show file tree
Hide file tree
Showing 33 changed files with 143 additions and 85 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^\.github$
^README(\.|\.[a-z]+\.)md$
^LICENSE\.md$
^cran.comments\.md$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ggd
Type: Package
Title: Gradational Gaussian Distribution Reference Class
Version: 1.0.1
Version: 1.0.2
Authors@R: c(
person( given = "Kimitsuna",
family = "Ura",
Expand Down
44 changes: 22 additions & 22 deletions R/ggd.1.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ f.t3.p <- list( function( x, m, s )
#' @field mix.type An integer which represents how to mix normal distributions
#' of the components.
#'
#' The type of the distribution model and the row number of \code{cmp}
#' field will be as follows with this value:
#' The type of the distribution model and the number of rows
#' in \code{cmp} field will be as follows with this value:
#' \itemize{
#' \item \code{0} : Normal distribution.
#' \code{cmp} has only 1 row.
Expand Down Expand Up @@ -389,7 +389,7 @@ GGD$methods(
#' Clear fields
#'
#' Clears all fields. The lengths of all vector fields and the number of rows
#' in the \code{cmp} field will be \code{0}.
#' in \code{cmp} field will be \code{0}.
#' @name clear
#' @aliases clear
#' @aliases \S4method{clear}{GGD}
Expand Down Expand Up @@ -417,7 +417,7 @@ GGD$methods(
)

################################################################################################
#' Adjust each row name of the cmp field.
#' Adjust each row name of cmp
#'
#' Sets each row name of \code{cmp} field according to \code{mix.type} field.
#' Normally, users of this class don't need to call this method directly.
Expand Down Expand Up @@ -474,7 +474,7 @@ GGD$methods(
)

################################################################################################
#' Adjust the kind.index field
#' Adjust kind and kind.index fields
#'
#' Sets \code{kind.index} and \code{kind} fields according to
#' \code{mix.type} and \code{cmp} fields.
Expand Down Expand Up @@ -637,7 +637,7 @@ GGD$methods(
)

################################################################################################
#' Index number of the kind of distribution
#' Index number of the kind
#'
#' Gets index numbers which represent the kinds of distributions.
#' @export
Expand Down Expand Up @@ -765,7 +765,7 @@ ggd.kind.index <- function( objs, undef.err = FALSE )
}

################################################################################################
#' String of the kind of distribution
#' String of the kind
#'
#' Gets the strings which represent the kinds of distributions.
#' @export
Expand Down Expand Up @@ -819,7 +819,7 @@ ggd.kind <- function( objs )
}

################################################################################################
#' Get mix.type according to grad
#' mix.type according to grad
#'
#' Gets the value for \code{mix.type} field of \code{GGD} object which is appropriate to
#' given \code{grad} value.
Expand Down Expand Up @@ -895,7 +895,7 @@ ggd.mix.type.for <- function( grad = c( "default", "normal", "h", "v", "v2", "v3
}

################################################################################################
#' Get mix.type according to kind.index
#' mix.type according to kind.index
#'
#' Gets a vector of integers of \code{mix.type}s
#' which are appropriate to the indicated index numbers of \code{ggd:::kinds}.
Expand Down Expand Up @@ -931,7 +931,7 @@ ggd.mix.type.for.kind.index <- function( kind.index )
}

################################################################################################
#' Get number of components according to the grad value and others
#' Number of components according to grad
#'
#' Gets the number of components for \code{cmp} field of \code{GGD} object
#' which is appropriate to given \code{grad} or \code{mix.type} argument.
Expand Down Expand Up @@ -1078,9 +1078,9 @@ GGD$methods(
)

################################################################################################
#' Judge if normal distribution
#' Judge if normal
#'
#' Referring only \code{cmp} field, checks if the distribution is a normal distribution.
#' Referring \code{cmp} field, checks if the distribution is essentially a normal distribution.
#' Note, this function does not check \code{kind} and \code{kind.index} fields.
#' @name is.normal
#' @aliases is.normal
Expand Down Expand Up @@ -1109,9 +1109,9 @@ GGD$methods(
)

################################################################################################
#' Judge if horizontal gradational distribution
#' Judge if horizontal
#'
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is constructed as
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is essentially
#' a horizontal gradational distribution.
#' When \code{mix.type = 4}, if it is essentially a horizontal gradational distribution,
#' this function returns \code{TRUE}.
Expand Down Expand Up @@ -1168,9 +1168,9 @@ GGD$methods(
)

################################################################################################
#' Judge if vertical gradation of 2 normal distributions
#' Judge if 2-component vertical
#'
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is constructed as
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is essentially
#' a vertical gradation of 2 normal distributions.
#' Even when \code{cmp} field has 3 rows with \code{mix.type = 3}, if the components of
#' the left-tail side and the right-tail side are the same, this function returns \code{TRUE},
Expand Down Expand Up @@ -1233,9 +1233,9 @@ GGD$methods(
)

################################################################################################
#' Judge if vertical gradation of 3 normal distributions
#' Judge if 3-component vertical
#'
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is constructed as
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is essentially
#' a vertical gradation of 3 normal distributions.
#' Note! when \code{mix.type = 4},
#' if the right-top-side and left-top-side components are the same
Expand Down Expand Up @@ -1295,9 +1295,9 @@ GGD$methods(
)

################################################################################################
#' Judge if horizontal-vertical gradation
#' Judge if horizontal-vertical
#'
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is constructed as
#' Referring \code{mix.type} and \code{cmp} field, checks if the distribution is essentially
#' a horizontal-vertical gradation of 4 (2x2) normal distributions.
#' @name is.hv
#' @aliases is.hv
Expand Down Expand Up @@ -1349,13 +1349,13 @@ GGD$methods(
}
else
{
return ( isTRUE( mix.type == 4 ) && !is.h() && !is.v2() )
return ( isTRUE( mix.type == 4 ) )
}
}
)

################################################################################################
#' Judge if symmetric distribution
#' Judge if symmetric
#'
#' Referring \code{mix.type} and \code{cmp} field,
#' checks if the probability density function is symmetric about the mean.
Expand Down
8 changes: 4 additions & 4 deletions R/ggd.apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Functions

################################################################################################
#' Apply functions to elements of cmp
#' Apply functions to cmp
#'
#' Applies a function to each element in the \code{cmp} field.
#' Different functions can be applied to \code{mean} column and \code{sd} column.
Expand Down Expand Up @@ -58,7 +58,7 @@
#' (e.g., \code{\link[ggd]{adjust.cmp}}, \code{\link[ggd]{round.cmp}}, etc.)
#' for the object of the 2nd argument, since they may update the values of the fields.
#'
#' This function does not change the number of rows of the \code{cmp} field,
#' This function does not change the number of rows in \code{cmp} field,
#' no matter what results are obtained.
#' @examples
#' a <- ggd.set.cmp( data.frame( mean = c( -0.5, 0, 0.5 ), sd = c( 1, 0.8, 1.2 ) ) )
Expand Down Expand Up @@ -137,12 +137,12 @@ apply.cmp.sub <- function( f, values, obj )
}

################################################################################################
#' Rounding of numbers in cmp
#' Rounding values in cmp
#'
#' Rounds the values of all elements in the \code{cmp} field and adjusts other fields
#' accordingly.
#' \code{\link[base]{round}} and \code{\link[base]{signif}} functions can apply.
#' These functions does not change the number of rows of \code{cmp} field,
#' These functions does not change the number of rows in \code{cmp} field,
#' no matter what results are obtained.
#' If an error occurs, these functions do not clear the object, but retains the values of
#' all fields.
Expand Down
4 changes: 2 additions & 2 deletions R/ggd.file.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Functions

################################################################################################
#' Read a composition from a CSV file
#' Read a composition
#'
#' Reads a CSV file recorded the composition of a \code{\link[ggd]{GGD}} object
#' and generates a \code{\link[ggd]{GGD}} object.
Expand Down Expand Up @@ -132,7 +132,7 @@ GGD$methods(
)

################################################################################################
#' Write the composition to a CSV file
#' Write the composition
#'
#' Writes the composition of a \code{\link[ggd]{GGD}} object as a CSV file.
#' Mean values and standard deviations of the components are recorded to a maximum length of
Expand Down
2 changes: 1 addition & 1 deletion R/ggd.mean.sd.R
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ calc.v.t4.via.integrate <- function( means, sds, mean = calc.mean( 4, means, sds
}

################################################################################################
#' Adjust the median, mean and sd fields
#' Adjust median, mean and sd fields
#'
#' Calculates the median, the mean and the standard deviation of the distribution model and
#' sets those values into the fields.
Expand Down
32 changes: 16 additions & 16 deletions R/ggd.nls.freq.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
#' You know a standard deviation must be a non-zero positive value.
#' But if you use standard deviations directly in the formula for \code{\link[stats]{nls}},
#' they will sometimes drop into negative values while the Gauss-Newton algorithm is running
#' and the algorithm will fail, even if it can reach to convergence if done better.
#' and the algorithm will fail, even if it can reach convergence if done better.
#'
#' So, to avoid such failures, we use square roots of standard deviations and
#' take squares of them in the formula for \code{\link[stats]{nls}}.
Expand Down Expand Up @@ -1123,7 +1123,7 @@ extract.freq.data <- function( data, x, freq )
data.ext <- extract.complete.x.y( data, x, freq, "freq" )
if ( nrow( data.ext ) < 3 )
{
stop( "Error: The row number of data is too small." )
stop( "Error: Too few rows for data." )
}

# Check if rows are sorted.
Expand Down Expand Up @@ -1298,14 +1298,14 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
# but closer to mean of the frequency distribution than "means".
# These are used when we do not want the initial mean values to be dispersed.
#
# sqrt.sd.mid:
# sqrt.sds.mid:
# Global or local standard deviation corresponding to around center of the range of
# the frequency distribution.
if ( is.na( start.level ) )
{
# Level NA: all parameters are NA.
means.mid <- means <- rep( NA_real_, 4 )
sqrt.sd.mid <- sqrt.sds <- rep( NA_real_, 4 )
sqrt.sds.mid <- sqrt.sds <- rep( NA_real_, 4 )

mean.lower <- mean.upper <- mean.inner <- mean.outer <- NA_real_
sqrt.sd.lower <- sqrt.sd.upper <- sqrt.sd.inner <- sqrt.sd.outer <- NA_real_
Expand All @@ -1320,7 +1320,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
sqrt.sd.lower <- sqrt.sd.upper <- sqrt.sd.inner <- sqrt.sd.outer <- sqrt( data.sd )

means.mid <- rep( data.mean, 4 )
sqrt.sd.mid <- sqrt( data.sd )
sqrt.sds.mid <- sqrt( data.sd )
}
else if ( start.level == 1 )
{
Expand Down Expand Up @@ -1352,7 +1352,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
}, 0 )

means.mid <- rep( data.mean, 4 )
sqrt.sd.mid <- sqrt( data.sd )
sqrt.sds.mid <- sqrt( data.sd )
}
else if ( start.level >= 2 )
{
Expand Down Expand Up @@ -1381,7 +1381,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
sqrt.sd.outer <- sqrt( ( ms[[1]]$sd + ms[[4]]$sd ) / 2 )

means.mid <- rep( data.mean, 4 )
sqrt.sd.mid <- sqrt( data.sd )
sqrt.sds.mid <- sqrt( data.sd )

if ( start.level == 3 )
{
Expand All @@ -1393,7 +1393,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
c( sep$data[[1]][lengths[1]], sep$data[[4]][1] ) )

means.mid <- rep( ms$mean, 4 )
sqrt.sd.mid <- sqrt( ms$sd )
sqrt.sds.mid <- sqrt( ms$sd )
}
else
{
Expand Down Expand Up @@ -1437,7 +1437,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
{
means.mid <- means <- obj$cmp$mean[c( 1, 2, 4, 3 )]
sqrt.sds <- sqrt( obj$cmp$sd[c( 1, 2, 4, 3 )] )
sqrt.sd.mid <- ( sqrt.sds[2] + sqrt.sds[3] ) / 2
sqrt.sds.mid <- ( sqrt.sds[2] + sqrt.sds[3] ) / 2
}
else
{
Expand All @@ -1454,7 +1454,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
sqrt.sd.inner <- sqrt.sds[2]
sqrt.sd.outer <- sqrt.sds[1]

sqrt.sd.mid <- sqrt.sds[2]
sqrt.sds.mid <- sqrt.sds[2]
}
}
}
Expand All @@ -1466,7 +1466,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
# via Normal Distribution
fm <- d ~ dnorm( x, mean, sqrt.sd^2 )

start <- list( mean = means.mid[1], sqrt.sd = sqrt.sd.mid )
start <- list( mean = means.mid[1], sqrt.sd = sqrt.sds.mid )
}
else
{
Expand All @@ -1478,7 +1478,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
fm <- d ~ ( dnorm( x, mean.1, sqrt.sd^2 ) + dnorm( x, mean.2, sqrt.sd^2 ) ) / 2
start <- list( mean.1 = mean.lower,
mean.2 = mean.upper,
sqrt.sd = sqrt.sd.mid )
sqrt.sd = sqrt.sds.mid )
}
else if ( eq.mean )
{
Expand Down Expand Up @@ -1507,7 +1507,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star

start <- list( mean.1 = mean.lower,
mean.2 = mean.upper,
sqrt.sd = sqrt.sd.mid )
sqrt.sd = sqrt.sds.mid )
}
else if ( eq.mean )
{
Expand Down Expand Up @@ -1543,7 +1543,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star

start <- list( mean.1 = mean.outer,
mean.2 = mean.inner,
sqrt.sd = sqrt.sd.mid )
sqrt.sd = sqrt.sds.mid )
}
else if ( eq.mean )
{
Expand Down Expand Up @@ -1576,7 +1576,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
start <- list( mean.1 = means[1],
mean.2 = mean.inner,
mean.3 = means[4],
sqrt.sd = sqrt.sd.mid )
sqrt.sd = sqrt.sds.mid )
}
else if ( eq.mean )
{
Expand Down Expand Up @@ -1620,7 +1620,7 @@ get.nls.params <- function( x, freq, total, mix.type, grad, eq.mean, eq.sd, star
mean.1.2 = means[2],
mean.2.1 = means[4],
mean.2.2 = means[3],
sqrt.sd = sqrt.sd.mid )
sqrt.sd = sqrt.sds.mid )
}
else if ( eq.mean )
{
Expand Down
2 changes: 1 addition & 1 deletion R/ggd.set.cmp.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ GGD$methods(
)

################################################################################################
#' Adjust the cmp field
#' Adjust cmp field
#'
#' Simplifies the components in \code{cmp} field with retaining
#' the substance of the distribution. Also, you can make \code{cmp} field redundant inversely.
Expand Down
2 changes: 1 addition & 1 deletion R/ggd.trace.q.R
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ GGD$methods(
mix.type.seq <- c( mix.type,
mix.type.seq[mix.type.seq != mix.type] )

# In order to attempt to retain number of rows of cmp field when mix.type = 3,
# In order to attempt to retain number of rows in cmp field when mix.type = 3,
# make sequences of values to set grad values.
if ( mix.type == 3 && nrow( cmp ) == 2 )
{
Expand Down
Loading

0 comments on commit 24b5146

Please sign in to comment.