Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/cran/sns
11 November 2022, 14:07:59 UTC
  • Code
  • Branches (8)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/0.9
    • refs/tags/0.9.1
    • refs/tags/1.0.0
    • refs/tags/1.1.0
    • refs/tags/1.1.1
    • refs/tags/1.1.2
    • refs/tags/1.2.2
    No releases to show
  • d8f0567
  • /
  • R
  • /
  • bayesGLM.R
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:ed1154ebc6632bf2fcb3694817d64fecab6d275c
origin badgedirectory badge Iframe embedding
swh:1:dir:87a88e6a01e89804125e3226849542ff2c22282b
origin badgerevision badge
swh:1:rev:b3d1d3be7c03cbb1a53aa7b68dac59b8c31f46e4
origin badgesnapshot badge
swh:1:snp:218ce733af7de6247148caa3cf8c71ef1c66e614
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: b3d1d3be7c03cbb1a53aa7b68dac59b8c31f46e4 authored by Asad Hasan on 26 August 2014, 00:00:00 UTC
version 0.9.1
Tip revision: b3d1d3b
bayesGLM.R
# A closure which generates a function, gradient, Hessian evaluator
# for log-likelihood functions of 4 types of GLMs.
#
# Args:
#   N - number of observations
#   K - number of variables
#   glmtype - must be one of the 4 strings
#   X - data matrix of the explanatory variable, must have N rows & K cols
#   y - vector having the dependent vaiable (reponse) corresponging to X
# Output:
#   Am evaluator which can be passes to sns()
glmfgh <- function(N, K, glmtype = "logistic", X=NULL, y=NULL) 
{
  # Check user supplied data for consistency
  if (!is.null(X)){
      stopifnot(!is.matrix(X) || ncol(X) != K || nrow(X) != N)
      stopifnot(!is.null(y) || length(y) != N)
  }

  # Set the link & distribution for specified GLM
  if (glmtype == "logistic")
      base.func <- ll_bern_logit
  else if (glmtype == "poisson")
      base.func <- ll_pois_log
  else if (glmtype == "exponential")
      base.func <- ll_exp_log
  else if (glmtype == "geometric")
      base.func <- ll_geom_logit
  else
      stop(paste("Unrecognized Arg 'glmtype'. Must be one of:",
                 "logistic, poisson, exponential, geomteric."))

  if (is.null(X) || is.null(y)) {
      # Generate simulated data
      stopifnot(N > K)
      data <- simGLM(N, K, glmtype = glmtype) 
      model.coef <- data$coef
      y <- data$df$y
      data$df$y <- NULL
      X <- data.matrix(data$df)
      data$df$y <- y 
  }

  # function, gradient, Hessian evaluator
  sns.fghEval <- function(beta, ...)
  {
      out <- ll_1par_expand(beta, X, y, base.func)
      return(list("f" = out$f, "g" = out$g, "h" = out$h))
  }
 
  return(sns.fghEval)
}

# Simulates data for a generalized linear model
# N - number of observations
# K - number of variables
# glmtype - must be one of: logistic, poisson, exponential, geomteric
simGLM <- function(N, K, glmtype="logistic")
{
  set.seed(exp(1));
  stopifnot(K >= 1)
  stopifnot(N > K)

  # Generate data matrix
  sim.df <-  matrix(c(rep(1, N), runif(N * (K - 1), min = -1, max = 1)), 
                    nrow = N, ncol = K)
  # Generate coefficient vec 
  coeff <- runif(K, -.5, .5)
 
  # Assign var names, first data var is the Intercept 
  colnames(sim.df) <- paste0("x", seq(1, K))

  # Compute linear predictors 
  eta <- sim.df %*% matrix(coeff, nrow = length(coeff), ncol = 1)
  
  # Combine into a data.frame
  sim.df <- data.frame(sim.df)
 
  # Compute response
  if (glmtype == "logistic")
      sim.df$y <- as.numeric(sapply(eta, function(x) 1/(1+exp(-x))) >= runif(N))
  else if (glmtype == "poisson")
      sim.df$y <- rpois(n=N, lambda = exp(eta))
  else if (glmtype == "exponential")
      sim.df$y <- rexp(n=N, rate = exp(eta))
  else if (glmtype == "geometric")
      sim.df$y <- rgeom(n=N, prob = sapply(eta, function(x) 1/(1+exp(-x))))
  else
      stop(paste("Unrecognized Arg 'glmtype'. Must be one of:", 
                 "logistic, poisson, exponential, geomteric."))

  # Return data and coefficients
  output <- list(df = sim.df, coef = coeff, glmtype = glmtype)
}

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top