bfsl
Best-fit straight line of bivariate data with errors in both coordinates.
Science Score: 57.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 10 DOI reference(s) in README -
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.8%) to scientific vocabulary
Last synced: 7 months ago
·
JSON representation
·
Repository
Best-fit straight line of bivariate data with errors in both coordinates.
Basic Info
- Host: GitHub
- Owner: pasturm
- License: other
- Language: R
- Default Branch: master
- Size: 351 KB
Statistics
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 2
Created over 7 years ago
· Last pushed over 3 years ago
Metadata Files
Readme
Changelog
License
Citation
README.Rmd
---
output:
github_document
# html_document:
# self_contained: no
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# R package bfsl: Best-fit Straight Line
[](https://github.com/pasturm/bfsl/actions)
[](https://codecov.io/gh/pasturm/bfsl)
[](https://cran.r-project.org/package=bfsl)
[](https://cran.r-project.org/package=bfsl)
[](https://cran.r-project.org/package=bfsl)
[](https://www.repostatus.org/#active)
### How to fit a straight line through a set of points with errors in both coordinates?
The solution for the best-fit straight line to independent points with normally distributed errors in both _x_ and _y_ is known e.g. from York ([1966](#york66), [1968](#york68), [2004](#york04)). It provides unbiased estimates of the intercept, slope and standard errors of the best-fit straight line, even when the _x_ and _y_ errors are correlated.
The bfsl package implements York's general solution and provides the best-fit straight line of bivariate data with errors in both coordinates.
Other commonly used least-squares estimation methods, such as ordinary least-squares regression, orthogonal distance regression (also called major axis regression), geometric mean regression (also called reduced major axis or standardised major axis regression) or Deming regression are all special cases of York’s solution and only valid under particular measurement conditions.
## Examples
```{r summary, out.width="75%", dpi=300}
library(bfsl)
fit = bfsl(pearson_york_data)
summary(fit)
```
```{r plot, out.width="75%", dpi=300}
plot(fit)
ols = bfsl(pearson_york_data, sd_x = 0, sd_y = 1)
abline(coef = ols$coef[,1], lty = 2)
legend("topright", c("best-fit straight line", "ordinary least squares"), lty = c(1,2))
```
```{r confidence, out.width="75%", dpi=300}
# with confidence interval
df = as.data.frame(fit$data)
newx = seq(min(df$x-df$sd_x), max(df$x+df$sd_x), length.out = 100)
preds = predict(fit, newdata = data.frame(x=newx), interval = 'confidence')
# plot
plot(y ~ x, data = df, type = 'n', xlim = c(min(x-sd_x), max(x+sd_x)),
ylim = c(min(y-sd_y), max(y+sd_y)), las = 1)
grid()
polygon(c(rev(newx), newx), c(rev(preds[ ,3]), preds[ ,2]), col = 'grey90', border = NA)
abline(coef = fit$coef[,1], lty = 1)
points(df$x, df$y)
arrows(df$x, df$y-df$sd_y, df$x, df$y+df$sd_y, length = 0.05, angle = 90, code = 3)
arrows(df$x-df$sd_x, df$y, df$x+df$sd_x, df$y, length = 0.05, angle = 90, code = 3)
```
```{r ggplot, out.width="60%", dpi=300}
# with ggplot2
library(ggplot2)
ggplot(data = df, aes(x = x, y = y)) +
geom_point() +
geom_smooth(method = bfsl, method.args = list(sd_x = df$sd_x, sd_y = df$sd_y)) +
geom_errorbar(aes(ymin = y-sd_y, ymax = y+sd_y), width = 0.05) +
geom_errorbarh(aes(xmin = x-sd_x, xmax = x+sd_x), height = 0.05)
```
```{r broom tidier, out.width="60%", dpi=300}
# broom tidier methods
tidy(fit, conf.int = TRUE)
glance(fit)
augment(fit, newdata = data.frame(x = c(2:6)))
```
## Installation
Install bfsl from CRAN with:
```{r cran_install, eval=FALSE}
install.packages("bfsl")
```
Install the development version from GitHub with:
```{r github_install, eval=FALSE}
if (!require("remotes")) { install.packages("remotes") }
remotes::install_github("pasturm/bfsl")
```
See the [NEWS file](https://github.com/pasturm/bfsl/blob/master/NEWS.md) for latest release notes.
## References
York, D. (1966). Least-squares fitting of a straight line. _Canadian Journal of Physics_, 44(5), 1079–1086, https://doi.org/10.1139/p66-090
York, D. (1968). Least squares fitting of a straight line with correlated errors. _Earth and Planetary Science Letters_, 5, 320–324,
https://doi.org/10.1016/S0012-821X(68)80059-7
Williamson, J. H. (1968). Least-squares fitting of a straight line,
_Canadian Journal of Physics_, 46(16), 1845-1847, https://doi.org/10.1139/p68-523
York, D. et al. (2004). Unified equations for the slope, intercept, and
standard errors of the best straight line, _American Journal of Physics_, 72, 367-375, https://doi.org/10.1119/1.1632486
Cantrell, C. A. (2008). Technical Note: Review of methods
for linear least-squares fitting of data and application to atmospheric chemistry problems,
_Atmospheric Chemistry and Physics_, 8, 5477-5487, https://acp.copernicus.org/articles/8/5477/2008/
Wehr, R. and Saleska, S. R. (2017). The long-solved problem of the best-fit straight line: application to isotopic mixing lines, _Biogeosciences_, 14, 17-29, https://doi.org/10.5194/bg-14-17-2017
Owner
- Name: Patrick Sturm
- Login: pasturm
- Kind: user
- Location: Thun, Switzerland
- Repositories: 2
- Profile: https://github.com/pasturm
Citation (CITATION.cff)
# -----------------------------------------------------------
# CITATION file created with {cffr} R package, v0.1.1
# See also: https://docs.ropensci.org/cffr/
# -----------------------------------------------------------
cff-version: 1.2.0
message: 'To cite package "bfsl" in publications use:'
type: software
license: MIT
title: 'bfsl: Best-Fit Straight Line'
version: 0.2.0
abstract: How to fit a straight line through a set of points with errors in both coordinates?
The 'bfsl' package implements the York regression (York, 2004 <doi:10.1119/1.1632486>).
It provides unbiased estimates of the intercept, slope and standard errors for the
best-fit straight line to independent points with (possibly correlated) normally
distributed errors in both x and y. Other commonly used errors-in-variables methods,
such as orthogonal distance regression, geometric mean regression or Deming regression
are special cases of the 'bfsl' solution.
authors:
- family-names: Sturm
given-names: Patrick
email: sturm@tofwerk.com
preferred-citation:
type: manual
title: 'bfsl: Best-Fit Straight Line'
authors:
- family-names: Sturm
given-names: Patrick
email: sturm@tofwerk.com
version: 0.2.0
abstract: How to fit a straight line through a set of points with errors in both
coordinates? The 'bfsl' package implements the York regression (York, 2004 <doi:10.1119/1.1632486>).
It provides unbiased estimates of the intercept, slope and standard errors for
the best-fit straight line to independent points with (possibly correlated) normally
distributed errors in both x and y. Other commonly used errors-in-variables methods,
such as orthogonal distance regression, geometric mean regression or Deming regression
are special cases of the 'bfsl' solution.
repository: https://CRAN.R-project.org/package=bfsl
repository-code: https://github.com/pasturm/bfsl
url: https://github.com/pasturm/bfsl
date-released: '2021-09-23'
contact:
- family-names: Sturm
given-names: Patrick
email: sturm@tofwerk.com
license: MIT
year: '2021'
repository: https://CRAN.R-project.org/package=bfsl
repository-code: https://github.com/pasturm/bfsl
url: https://github.com/pasturm/bfsl
date-released: '2021-09-23'
contact:
- family-names: Sturm
given-names: Patrick
email: sturm@tofwerk.com
GitHub Events
Total
Last Year
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Patrick Sturm | s****m@t****h | 18 |
| Patrick Sturm | s****m@t****m | 14 |
Committer Domains (Top 20 + Academic)
tofwerk.com: 1
tofwerk.ch: 1
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 2
- Total pull requests: 0
- Average time to close issues: 3 months
- Average time to close pull requests: N/A
- Total issue authors: 1
- Total pull request authors: 0
- Average comments per issue: 5.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- japhir (2)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 253 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 2
- Total maintainers: 1
cran.r-project.org: bfsl
Best-Fit Straight Line
- Homepage: https://github.com/pasturm/bfsl
- Documentation: http://cran.r-project.org/web/packages/bfsl/bfsl.pdf
- License: MIT + file LICENSE
-
Latest release: 0.2.0
published over 4 years ago
Rankings
Dependent repos count: 24.0%
Forks count: 27.8%
Dependent packages count: 28.8%
Average: 30.1%
Stargazers count: 30.9%
Downloads: 39.0%
Maintainers (1)
Last synced:
8 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.5.0 depends
- generics * imports
- dplyr * suggests
- testthat * suggests
- tibble * suggests
.github/workflows/check-standard.yaml
actions
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite