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

  • dd9e837
  • /
  • test
  • /
  • test_zcpglm.R
Raw File Download

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
content badge
swh:1:cnt:63013a6161208da97e048867283e483f17a7eeaa
directory badge
swh:1:dir:3d4e1d33669c97accb580cef4ff3f05a314d2417

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
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_zcpglm.R
if (FALSE){
library(cplm)
library(tweedie)
library(pscl)

fit1 <- cpglm(RLD ~ factor(Stock) ,
  data = fineroot)
fit2 <- cpglm(RLD ~ factor(Zone) ,
  data = fineroot)
setwd("C:\\Documents and Settings\\CAB2007\\My Documents\\2011\\cplm")
#setwd("~/2011/cplm")
source("./R/classMethods.R")
source("./R/utilities.R")

# simulate data for use 
gamma <- c(-1, 0.2)
beta <- coef(fit1)
beta[1] <- beta[1] + 1
p <- fit1$p
phi <- fit1$phi
Z <- model.matrix(fit2)
dd <- exp(Z %*% gamma)
q <- dd / (1 + dd)
n <- nrow(fineroot)
X <- model.matrix(fit1)
s <- rbinom(n, 1, q)
mu<- as.numeric(exp(X %*%beta))
fineroot$y <- rtweedie(n, power = p, phi = phi, mu = mu)
fineroot$y[s == 1] <- 0


link="log"
control=list()
trace=T
contrasts = NULL

zcpglm <- function(formula, link = "log", data, weights, offset, 
                  subset, na.action = NULL, contrasts = NULL, 
                  control = list(), chunksize = 0, ...) {}

call <- match.call(zcpglm,call("zcpglm", y ~ factor(Stock) || factor(Zone),
  data=fineroot))
formula <- y ~ factor(Stock) || factor(Zone)

system.time(f1 <- zcpglm(y ~ factor(Stock) || factor(Zone), data=fineroot, control = list(trace =1)))
coef(f1)



#########################################
# run simulations
#########################################
library(cplm)
library(pscl)

fit1 <- cpglm(RLD ~ factor(Stock) ,
  data = fineroot)
fit2 <- cpglm(RLD ~ factor(Zone) ,
  data = fineroot)

# simulate data for use 
gamma <- c(-1, 0.2)
beta <- coef(fit1)
beta[1] <- beta[1] + 1
p <- fit1$p
phi <- fit1$phi
Z <- model.matrix(fit2)
dd <- exp(Z %*% gamma)
q <- dd / (1 + dd)
n <- nrow(fineroot)
X <- model.matrix(fit1)

nsim <- 100 
sims<- matrix(0, nsim, length(gamma)+ length(beta) + 2)

set.seed(10)
for ( i in 1:nsim){
  s <- runif(n) 
  s[s > q] <- 0
  s[s != 0] <- 1
  fineroot$y <- tweedie::rtweedie(n, power = p, phi = phi, mu = as.numeric(exp(X %*%beta)))
  fineroot$y[s == 1] <- 0
  f1 <- zcpglm(y ~ factor(Stock) || factor(Zone), data=fineroot)
  sims[i,] <- as.numeric(c(unlist(coef(f1)), f1$phi, f1$p))
}

apply(sims,2,median)
c(gamma, beta, phi, p)
}

back to top

Software Heritage — Copyright (C) 2015–2026, 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— Content policy— Contact— JavaScript license information— Web API