From 7091d3738e7e55acb20edb88772b228f6f5b6c98 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 31 Oct 2019 01:55:01 +0100 Subject: Add likelihood ratio test and other methods, fixes The likelihood ratio test method is lrtest, in addition, methods for update and residuals were added. --- man/confint.mkinfit.Rd | 3 ++- man/logLik.mkinfit.Rd | 9 +++++---- man/lrtest.mkinfit.Rd | 43 +++++++++++++++++++++++++++++++++++++++++++ man/mkinfit.Rd | 4 +++- man/reexports.Rd | 16 ++++++++++++++++ man/residuals.mkinfit.Rd | 24 ++++++++++++++++++++++++ man/update.mkinfit.Rd | 29 +++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 man/lrtest.mkinfit.Rd create mode 100644 man/reexports.Rd create mode 100644 man/residuals.mkinfit.Rd create mode 100644 man/update.mkinfit.Rd (limited to 'man') diff --git a/man/confint.mkinfit.Rd b/man/confint.mkinfit.Rd index bad73407..ee07c9c1 100644 --- a/man/confint.mkinfit.Rd +++ b/man/confint.mkinfit.Rd @@ -71,7 +71,8 @@ system.time(ci_profile <- confint(f_d_1, cores = 1, quiet = TRUE)) # c("k_parent_sink", "k_parent_m1", "k_m1_sink", "sigma"), cores = 1)) # If we exclude parent_0 (the confidence of which is often of minor interest), we get a nice # performance improvement from about 30 seconds to about 12 seconds -# system.time(ci_profile_no_parent_0 <- confint(f_d_1, c("k_parent_sink", "k_parent_m1", "k_m1_sink", "sigma"), cores = 4)) +# system.time(ci_profile_no_parent_0 <- confint(f_d_1, +# c("k_parent_sink", "k_parent_m1", "k_m1_sink", "sigma"), cores = 4)) ci_profile ci_quadratic_transformed <- confint(f_d_1, method = "quadratic") ci_quadratic_transformed diff --git a/man/logLik.mkinfit.Rd b/man/logLik.mkinfit.Rd index bb2c2957..502fb4d7 100644 --- a/man/logLik.mkinfit.Rd +++ b/man/logLik.mkinfit.Rd @@ -17,10 +17,11 @@ An object of class \code{\link{logLik}} with the number of estimated as attribute. } \description{ -This function simply calculates the product of the likelihood densities -calculated using \code{\link{dnorm}}, i.e. assuming normal distribution, -with of the mean predicted by the degradation model, and the standard -deviation predicted by the error model. +This function returns the product of the likelihood densities of each +observed value, as calculated as part of the fitting procedure using +\code{\link{dnorm}}, i.e. assuming normal distribution, and with the means +predicted by the degradation model, and the standard deviations predicted by +the error model. } \details{ The total number of estimated parameters returned with the value of the diff --git a/man/lrtest.mkinfit.Rd b/man/lrtest.mkinfit.Rd new file mode 100644 index 00000000..b38732b4 --- /dev/null +++ b/man/lrtest.mkinfit.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/lrtest.mkinfit.R +\name{lrtest.mkinfit} +\alias{lrtest.mkinfit} +\title{Likelihood ratio test for mkinfit models} +\usage{ +\method{lrtest}{mkinfit}(object, object_2 = NULL, ...) +} +\arguments{ +\item{object}{An \code{\link{mkinfit}} object} + +\item{object_2}{Optionally, another mkinfit object fitted to the same data.} + +\item{\dots}{Argument to \code{\link{mkinfit}}, passed to +\code{\link{update.mkinfit}} for creating the alternative fitted object.} +} +\description{ +Compare two mkinfit models based on their likelihood. If two fitted +mkinfit objects are given as arguments, it is checked if they have been +fitted to the same data. It is the responsibility of the user to make sure +that the models are nested, i.e. one of them has less degrees of freedom +and can be expressed by fixing the parameters of the other. +} +\details{ +Alternatively, an argument to mkinfit can be given which is then passed +to \code{\link{update.mkinfit}} to obtain the alternative model. + +The comparison is then made by the \code{\link[lmtest]{lrtest.default}} +method from the lmtest package. The model with the higher number of fitted +parameters (alternative hypothesis) is listed first, then the model with the +lower number of fitted parameters (null hypothesis). +} +\examples{ +\dontrun{ +test_data <- subset(synthetic_data_for_UBA_2014[[12]]$data, name == "parent") +sfo_fit <- mkinfit("SFO", test_data, quiet = TRUE) +dfop_fit <- mkinfit("DFOP", test_data, quiet = TRUE) +lrtest(dfop_fit, sfo_fit) +lrtest(sfo_fit, dfop_fit) +lrtest(dfop_fit, error_model = "tc") +lrtest(dfop_fit, fixed_parms = c(k2 = 0)) +} +} diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index d9afb753..e58e61e2 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -65,7 +65,9 @@ default values. Otherwise, inital values for all error model parameters must be given.} \item{fixed_parms}{The names of parameters that should not be optimised but -rather kept at the values specified in \code{parms.ini}.} +rather kept at the values specified in \code{parms.ini}. Alternatively, +a named numeric vector of parameters to be fixed, regardless of the values +in parms.ini.} \item{fixed_initials}{The names of model variables for which the initial state at time 0 should be excluded from the optimisation. Defaults to all diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 00000000..bb77acc5 --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/lrtest.mkinfit.R +\docType{import} +\name{reexports} +\alias{reexports} +\alias{lrtest} +\title{Objects exported from other packages} +\keyword{internal} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{lmtest}{\code{\link[lmtest]{lrtest}}} +}} + diff --git a/man/residuals.mkinfit.Rd b/man/residuals.mkinfit.Rd new file mode 100644 index 00000000..407b89b9 --- /dev/null +++ b/man/residuals.mkinfit.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/residuals.mkinfit.R +\name{residuals.mkinfit} +\alias{residuals.mkinfit} +\title{Extract residuals from an mkinfit model} +\usage{ +\method{residuals}{mkinfit}(object, standardized = FALSE, ...) +} +\arguments{ +\item{object}{An \code{\link{mkinfit}} object} + +\item{standardized}{Should the residuals be standardized by dividing by the +standard deviation obtained from the fitted error model?} + +\item{\dots}{Not used} +} +\description{ +Extract residuals from an mkinfit model +} +\examples{ +f <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE) +residuals(f) +residuals(f, standardized = TRUE) +} diff --git a/man/update.mkinfit.Rd b/man/update.mkinfit.Rd new file mode 100644 index 00000000..aae1fbb4 --- /dev/null +++ b/man/update.mkinfit.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/update.mkinfit.R +\name{update.mkinfit} +\alias{update.mkinfit} +\title{Update an mkinfit model with different arguments} +\usage{ +\method{update}{mkinfit}(object, ..., evaluate = TRUE) +} +\arguments{ +\item{object}{An mkinfit object to be updated} + +\item{\dots}{Arguments to \code{\link{mkinfit}} that should replace +the arguments from the original call. Arguments set to NULL will +remove arguments given in the original call} + +\item{evaluate}{Should the call be evaluated or returned as a call} +} +\description{ +This function will return an updated mkinfit object. The fitted degradation +model parameters from the old fit are used as starting values for the +updated fit. Values specified as 'parms.ini' and/or 'state.ini' will +override these starting values. +} +\examples{ +\dontrun{ +fit <- mkinfit("DFOP", subset(FOCUS_2006_D, value != 0), quiet = TRUE) +update(fit, error_model = "tc") +} +} -- cgit v1.2.1