Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options to set initial mu0 and r0 for optim() in cnbinom.pars() #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions R/cnbinom.pars_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(stringr)
# cnbinom.pars is a function that outputs mu and r from univariate censored table input
# assume negative binomial

cnbinom.pars<-function (censoredtable){
cnbinom.pars<-function (censoredtable, mu0 = 100, r0 = 100, warn = -1, ...){


# make probabilities if not already
Expand Down Expand Up @@ -283,11 +283,12 @@ findtypeofcensoring_univariatetable<-function (univariatefreqtable){

# optimize mu and r in loglikelihood_univariatecase
# hide warnings...
options(warn=-1)
options(warn = warn)

fixdata_univariatecase_output=fixdata_univariatecase(censoredtable)
op<- optim(par=c(100,100),
op<- optim(par=c(mu0, r0),
fn =loglikelihood_univariatecase,
fixdata_univariatecase_output=fixdata_univariatecase_output)
fixdata_univariatecase_output=fixdata_univariatecase_output, ...)
final<-op$par
mu = final[1]
r = final[2]
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ library(revengc)
## Usage
`cnbinom.pars()` has the following format
```
cnbinom.pars(censoredtable)
cnbinom.pars(censoredtable, mu0 = 100, r0 = 100, warn = -1, ...)
```

where a description of the argument directly below

* **censoredtable** - A frequency table (censored and/or uncensored). A data.frame and matrix are acceptable classes. See Table format section below.

* **mu0, r0** starting values for `mu` and `r` used by optim.
* **warn** - Value used for `options(warn)` during `optim()` fitting.
`-1` suppresses warnings
* **...** - Additional arguments to be passed to `optim()`

`rec()` has the following format where a description of each argument is found below

Expand Down