Skip to content

Commit

Permalink
added somerton function
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk118 committed Oct 21, 2024
1 parent 9073a61 commit 10c1c59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(broken_stick_stevens)
export(fake_crustaceans)
export(infl_pt)
export(regrans_fun)
export(somerton_fun)
export(two_line_logistic)
export(two_line_stevens)
import(ggplot2)
Expand Down
4 changes: 2 additions & 2 deletions R/broken_stick.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ broken_stick <- function(dat,
}

if (is.null(lower)) {
lower <- stats::quantile(dat$xvar, 0.2)
lower <- stats::quantile(dat[[xvar]], 0.2)
}

if (is.null(upper)) {
upper <- stats::quantile(dat$xvar, 0.8)
upper <- stats::quantile(dat[[xvar]], 0.8)
}

if ("chngpt" %in% method | "all" %in% method) {
Expand Down
21 changes: 17 additions & 4 deletions vignettes/classification.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ ggplot() +

hclust, kmeans, hkmeans, PAM, OPTICS, DBSCAN, HDBSCAN, Somerton method, mclust

## Somerton method

```{r}
out_df <- somerton_fun(fc, xvar = "x", yvar = "y")[[1]]
mod <- glm(data = out_df,
pred_mat_num ~ x,
family = binomial(link = "logit"))
unname(-coef(mod)[1] / coef(mod)[2])
```


# Other classification methods

## Inflection point discriminant method
Expand All @@ -103,8 +114,8 @@ ggplot() +

The line can then be used to classify each point as immature and mature, enabling logistic regression to be applied to estimate SM50:
```{r}
fc_infl_pt <- fc %>% mutate(pred_mat = as.factor(if_else(y/x > disc, 1, 0)),
correct = if_else(pred_mat == mature, TRUE, FALSE))
fc_infl_pt <- fc %>% mutate(pred_mat = as.factor(if_else(y / x > disc, 1, 0)),
correct = if_else(pred_mat == mature, TRUE, FALSE))
```

```{r}
Expand Down Expand Up @@ -132,10 +143,12 @@ if (rlang::is_installed("patchwork")) {
```

```{r}
infl_pt_mod <- glm(pred_mat ~ x, family=binomial(link="logit"), data=fc_infl_pt)
infl_pt_mod <- glm(pred_mat ~ x,
family = binomial(link = "logit"),
data = fc_infl_pt)
# SM50 = -A/B
unname(-coef(infl_pt_mod)[1]/coef(infl_pt_mod)[2])
unname(-coef(infl_pt_mod)[1] / coef(infl_pt_mod)[2])
```


Expand Down

0 comments on commit 10c1c59

Please sign in to comment.