{"id":16703733,"url":"https://github.com/mbojan/lspline","last_synced_at":"2025-04-10T05:02:35.711Z","repository":{"id":63092609,"uuid":"82685489","full_name":"mbojan/lspline","owner":"mbojan","description":"R package: Linear Splines with Convenient Parameterizations","archived":false,"fork":false,"pushed_at":"2022-11-13T20:10:50.000Z","size":1354,"stargazers_count":8,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T06:11:54.891Z","etag":null,"topics":["generalized-linear-models","r","r-package","splines"],"latest_commit_sha":null,"homepage":"https://mbojan.github.io/lspline/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbojan.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-21T13:55:00.000Z","updated_at":"2025-03-22T11:17:24.000Z","dependencies_parsed_at":"2023-01-21T14:50:33.419Z","dependency_job_id":null,"html_url":"https://github.com/mbojan/lspline","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbojan%2Flspline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbojan%2Flspline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbojan%2Flspline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbojan%2Flspline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbojan","download_url":"https://codeload.github.com/mbojan/lspline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161270,"owners_count":21057554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generalized-linear-models","r","r-package","splines"],"created_at":"2024-10-12T19:09:18.130Z","updated_at":"2025-04-10T05:02:35.670Z","avatar_url":"https://github.com/mbojan.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: \n  github_document:\n    html_preview: true\nbibliography: vignettes/lspline.bib\neditor_options:\n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# `lspline`: Linear Splines with Convenient Parameterizations\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/mbojan/lspline/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mbojan/lspline/actions/workflows/R-CMD-check.yaml)\n[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/lspline?color=2ED968)](http://cranlogs.r-pkg.org/)\n[![cran version](http://www.r-pkg.org/badges/version/lspline)](https://cran.r-project.org/package=lspline)\n\u003c!-- badges: end --\u003e\n\n\nLinear splines with convenient parameterizations such that:\n\n- coefficients are slopes of consecutive segments\n- coefficients capture slope change at consecutive knots\n\nKnot locations can be specified\n\n- manually (`lspline()`)\n- at breaks dividing the range of `x` into `q` equal-frequency intervals (`qlspline()`)\n- at breaks dividing the range of `x` into `n` equal-width intervals (`elspline()`)\n\nInspired by Stata command `mkspline` and function `lspline()` from package **ares** [@r-ares]. As such, the implementation follows @greene2003econometric, chapter 7.5.2.\n\n\n\n## Installation\n\nFrom CRAN or development version using **remotes**:\n\n```{r install, eval=FALSE}\nremotes::install_github(\"mbojan/lspline\", build_vignettes = TRUE)\n```\n\n## Examples\n\nSee package [homepage](https://mbojan.github.io/lspline/) and the [vignette](https://mbojan.github.io/lspline/articles/lspline.html).\n\n\n\n```{r logo, include=FALSE, eval=FALSE}\nlibrary(hexSticker)\nlibrary(tidyverse)\nlibrary(ggforce)\n\n# 1 ----------------------------------------------------------------------------\nd1 \u003c- tibble::tribble(\n  ~x, ~y,\n  0, 0,\n  4, 1, # b = 1/4\n  8, -1, # b = 1/2\n  10, 2 # b = 3\n) \nd2 \u003c- tibble::tribble(\n  ~x, ~y,\n  4, 1,\n  6, 1.5\n)\nd3 \u003c- tibble::tribble(\n  ~x, ~y,\n  8, -1,\n  10, -2,\n)\n\narcs \u003c- tibble::tribble(\n  ~x0, ~y0, ~r, ~start, ~end,\n  4, 1, 0.5, pi/2 - atan(1/4), pi/2 + atan(1/2),\n  8, -1, 0.5, pi/2 - atan(3/2), pi/2 + atan(1/2)\n)\n\nd1 |\u003e\n  ggplot() +\n  geom_line(aes(x=x, y=y), data = d1, linetype = \"solid\") +\n  geom_line(aes(x=x, y=y), data = d2, linetype = \"dotted\") +\n  geom_line(aes(x=x, y=y), data = d3, linetype = \"dotted\") +\n  geom_arc(aes(x0 = x0, y0 = y0, r = r, start = start, end = end),\n           data = arcs) +\n  coord_fixed()\n\n\n# 2 ----------------------------------------------------------------------------\n\nd \u003c- tibble(\n  y = c(0, 2, 1, 1.5),\n  x = seq(along = y)\n)\n\nggplot() +\n  geom_line(aes(x=x, y=y), data = d, linetype = \"solid\") +\n  coord_fixed()\n  \n\n# 3 ----------------------------------------------------------------------------\n\nd \u003c- tibble::tribble(\n  ~x, ~y,\n  0, 0,\n  2, 2,\n  3, 3,\n  5, 1,\n  6, 0\n) |\u003e\n  map(embed, 2) |\u003e\n  imap(~ structure(.x, dimnames=list(NULL, paste0(.y, c('end', ''))))) |\u003e\n  map(as_tibble) |\u003e\n  bind_cols() |\u003e\n  mutate(\n    lt = rep(c(\"s\", \"d\"), length = 4)\n  )\n  \nd |\u003e\n  ggplot(aes(x=x, y=y, xend=xend, yend=yend)) +\n  geom_segment(data = filter(d, lt == \"s\")) +\n  scale_linetype_manual(\n    breaks = c(\"s\", \"d\"),\n    values = c(\"solid\", \"dotted\"),\n    guide = \"none\"\n  )\n\n\n# 4 ----------------------------------------------------------------------------\n\n# Generate data for the spline based on the sequence of values for 'y'.\n\ny \u003c- c(0, 3, 1, 2)\n\n# Solid line\nd_solid \u003c- tibble(x = seq(along=y), y = y)\n\n# Extends\nd_dashed \u003c- tibble::tribble(\n  ~x, ~y, ~xend, ~yend,\n  2, 3, 2.5, 4.5,\n  3, 1, 3.5, 0\n)\n\nd_arcs \u003c- tibble::tribble(\n  ~x0, ~y0, ~r, ~start, ~end,\n  2, 3, 0.5, pi/2 - atan(3), pi/2 + atan(2),\n  3, 1, 0.5, pi/2 - atan(1), pi/2 + atan(2)\n)\n\nd_labels \u003c- tibble::tribble(\n  ~x, ~y, ~label,\n  2, 3, \"beta[1]\",\n  3, 1, \"beta[2]\"\n)\n\np \u003c- ggplot() +\n  geom_line(aes(x=x, y=y), data = d_solid) +\n  geom_segment(aes(x=x, y=y, xend=xend, yend=yend), data = d_dashed, \n               linetype = \"dotted\"\n  ) +\n  geom_arc(aes(x0=x0, y0=y0, r=r, start=start, end=end), data = d_arcs) +\n  geom_label(aes(x=x, y=y, label=label), data = d_labels, parse = TRUE,\n             nudge_x = 0.25, nudge_y = 0) +\n  coord_fixed() +\n  theme_void()\n\nsticker(\n  p,\n  s_x = 1,\n  s_y = 1,\n  s_width = 2,\n  s_height = 2,\n  package = \"lspline\",\n) |\u003e plot()\n```\n\n\n\n## References\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbojan%2Flspline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbojan%2Flspline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbojan%2Flspline/lists"}