Skip to content

Commit

Permalink
Added the fit_growth_rate function
Browse files Browse the repository at this point in the history
  • Loading branch information
telkamp7 committed Oct 16, 2023
1 parent 5c3bb91 commit 4080695
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ Package: aedseo
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
person("First", "Last", , "first.last@example.com", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
person("Kasper", "Schou Telkamp", ,"ksst@ssi.dk", role = c("aut", "cre"),
comment = c(ORCID = "0009-0001-5126-0190"))
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Author@R: person("Kasper", "Schou Telkamp", email = "KSST@ssi.dk")
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Expand All @@ -19,5 +18,6 @@ Imports:
base,
magrittr,
MASS,
rlang,
stats,
tibble
1 change: 1 addition & 0 deletions R/aedseo-package.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @keywords internal
#' @aliases aedseo-package
"_PACKAGE"

## usethis namespace: start
Expand Down
42 changes: 42 additions & 0 deletions R/fit_growth_rate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@



fit_growth_rate <- function(
observations,
level = 0.95,
family = c(
stats::poisson(link = "log"),
stats::quasipoisson(link = "log")))
{

# Calculate the length of the series
n <- base::length(observations)

# Construct a data.frame wit growth rate data
growth_data <- stats::aggregate(
observations,
by = list(growth_rate = rep(1:n, each=1)),
FUN = sum)

# Fit the model using the specified family
growth_fit <- stats::glm(
formula = x ~ growth_rate,
data = growth_data,
family = family)

# Profile the model
growth_profile <- stats::profile(fitted = growth_fit)

# Collect the estimates
ans <- c(
stats::coef(object = growth_fit)["growth_rate"],
stats::confint(object = growth_profile,
parm = "growth_rate",
level = level))

return(list(
estimate = ans,
level = level,
family = family))

}
4 changes: 2 additions & 2 deletions man/aedseo-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4080695

Please sign in to comment.