### Install skellam Package from GitHub Source: https://github.com/monty-se/skellam/blob/master/README.md Installs the development version of the 'skellam' package directly from its GitHub repository. This requires the 'remotes' package to be installed first. ```R # install.packages("remotes") # Uncomment if needed remotes::install_github("monty-se/skellam") ``` -------------------------------- ### Example: Skellam Maximum Likelihood Estimation Source: https://github.com/monty-se/skellam/blob/master/README.md Shows how to use the skellam.mle function to estimate the parameters of a Skellam distribution from a dataset of differences (XminusY) and then print the results. ```R mle_result <- skellam.mle(XminusY) print(mle_result) ``` -------------------------------- ### Install skellam Package from CRAN Source: https://github.com/monty-se/skellam/blob/master/README.md Installs the latest stable version of the 'skellam' package from the Comprehensive R Archive Network (CRAN). This is the standard method for obtaining the package for use in R. ```R install.packages("skellam") ``` -------------------------------- ### Example: Skellam Density Plot Source: https://github.com/monty-se/skellam/blob/master/README.md Demonstrates how to generate Skellam random variates, compute their difference from Poisson samples, and plot the empirical density against the theoretical density calculated using dskellam. ```R N <- 5000 lambda1 <- 1.5 lambda2 <- 0.5 X <- rpois(N, lambda1) Y <- rpois(N, lambda2) XminusY <- X - Y Z <- rskellam(N, lambda1, lambda2) xseq <- seq(min(XminusY), max(XminusY)) plot(table(XminusY), main = "Empirical vs. Theoretical Density", xlab = "X - Y", ylab = "Frequency", pch = 1) points(xseq, N * dskellam(xseq, lambda1, lambda2), col = "blue", pch = 4) legend("topright", legend = c("Empirical", "Theoretical"), pch = c(1, 4), col = c("black", "blue")) ``` -------------------------------- ### Example: Skellam Regression Source: https://github.com/monty-se/skellam/blob/master/README.md Illustrates fitting a Skellam regression model. It involves simulating covariate data, generating Poisson outcomes based on the covariate, calculating their difference, and then fitting the regression model using skellam.reg. ```R set.seed(123) x_cov <- rnorm(N) y1 <- rpois(N, exp(1 + x_cov)) y2 <- rpois(N, exp(-1 + x_cov)) y_diff <- y2 - y1 reg_result <- skellam.reg(y_diff, x_cov) print(reg_result) ``` -------------------------------- ### Load MathJax for LaTeX Rendering Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This JavaScript code snippet dynamically loads the MathJax library to render mathematical equations, specifically TeX and MathML, within the HTML document. It's typically used in documentation pages to display mathematical formulas correctly. ```javascript (function () { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; document.getElementsByTagName("head")[0].appendChild(script); })(); ``` -------------------------------- ### Perform Skellam Maximum Likelihood Estimation Source: https://github.com/monty-se/skellam/blob/master/README.md Estimates the parameters of the Skellam distribution using maximum likelihood estimation (MLE) based on a provided vector of observed differences 'x'. ```R skellam.mle(x) ``` -------------------------------- ### Generate Skellam Random Variates Source: https://github.com/monty-se/skellam/blob/master/README.md Generates random numbers from the Skellam distribution. It requires the number of variates 'n' and the rate parameters 'lambda1' and 'lambda2'. ```R rskellam(n, lambda1, lambda2 = lambda1) ``` -------------------------------- ### Calculate Skellam Quantiles Source: https://github.com/monty-se/skellam/blob/master/README.md Returns the quantile function (inverse CDF) for the Skellam distribution. It requires a probability 'p' and the rate parameters 'lambda1' and 'lambda2'. Options for lower tail and log probabilities are available. ```R qskellam(p, lambda1, lambda2 = lambda1, lower.tail = TRUE, log.p = FALSE) ``` -------------------------------- ### CSS: Styling for Code Blocks and Document Elements Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This CSS defines various styles for the Skellam project documentation. It includes rules for code block formatting (white-space, overflow), specific text styles (smallcaps, underline), layout for columns and hanging indents, task lists, and general body and table styling. ```CSS code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} code { white-space: pre; } .sourceCode { overflow: visible; } pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } code span.at { color: #7d9029; } code span.bn { color: #40a070; } code span.bu { color: #008000; } code span.cf { color: #007020; font-weight: bold; } code span.ch { color: #4070a0; } code span.cn { color: #880000; } code span.co { color: #60a0b0; font-style: italic; } code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } code span.do { color: #ba2121; font-style: italic; } code span.dt { color: #902000; } code span.dv { color: #40a070; } code span.er { color: #ff0000; font-weight: bold; } code span.ex { } code span.fl { color: #40a070; } code span.fu { color: #06287e; } code span.im { color: #008000; font-weight: bold; } code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } code span.kw { color: #007020; font-weight: bold; } code span.op { color: #666666; } code span.ot { color: #007020; } code span.pp { color: #bc7a00; } code span.sc { color: #4070a0; } code span.ss { color: #bb6688; } code span.st { color: #4070a0; } code span.va { color: #19177c; } code span.vs { color: #4070a0; } code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } body { background-color: #fff; margin: 1em auto; max-width: 700px; overflow: visible; padding-left: 2em; padding-right: 2em; font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.35; } #TOC { clear: both; margin: 0 0 10px 10px; padding: 4px; width: 400px; border: 1px solid #CCCCCC; border-radius: 5px; background-color: #f6f6f6; font-size: 13px; line-height: 1.3; } #TOC .toctitle { font-weight: bold; font-size: 15px; margin-left: 5px; } #TOC ul { padding-left: 40px; margin-left: -1.5em; margin-top: 5px; margin-bottom: 5px; } #TOC ul ul { margin-left: -2em; } #TOC li { line-height: 16px; } table { margin: 1em auto; border-width: 1px; border-color: #DDDDDD; border-style: outset; border-collapse: collapse; } table th { border-width: 2px; padding: 5px; border-sty ``` -------------------------------- ### JavaScript: Apply Pandoc div.sourceCode Styles to pre.sourceCode Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This script iterates through style sheets to find Pandoc-specific styles for 'div.sourceCode' and applies them to 'pre.sourceCode' elements. This ensures consistent styling for code blocks across different Pandoc versions. ```JavaScript (function() { var sheets = document.styleSheets; for (var i = 0; i < sheets.length; i++) { if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue; try { var rules = sheets[i].cssRules; } catch (e) { continue; } var j = 0; while (j < rules.length) { var rule = rules[j]; // check if there is a div.sourceCode rule if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") { j++; continue; } var style = rule.style.cssText; // check if color or background-color is set if (rule.style.color === '' && rule.style.backgroundColor === '') { j++; continue; } // replace div.sourceCode by a pre.sourceCode rule sheets[i].deleteRule(j); sheets[i].insertRule('pre.sourceCode{' + style + '}', j); } } })(); ``` -------------------------------- ### Calculate Skellam Cumulative Distribution Function Source: https://github.com/monty-se/skellam/blob/master/README.md Computes the cumulative distribution function (CDF) of the Skellam distribution. It takes a quantile 'q', and the rate parameters 'lambda1' and 'lambda2'. Options for lower tail and log probabilities are available. ```R pskellam(q, lambda1, lambda2 = lambda1, lower.tail = TRUE, log.p = FALSE) ``` -------------------------------- ### R: Quantile Comparison Plot Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This snippet demonstrates how to compare the quantiles of a dataset 'Z' with the quantiles of a Skellam distribution. It generates a sequence of probabilities, calculates the quantiles for both the dataset and the Skellam distribution, and then plots them against each other. A red reference line (y=x) is added for visual comparison. ```R Sprob <- seq(0, 1, by = 1/100) qZ <- quantile(Z, prob = Sprob) plot(qZ, qskellam(Sprob, lambda1, lambda2)) abline(0, 1, col = "#FF000040") ``` -------------------------------- ### Calculate Skellam Probability Density Source: https://github.com/monty-se/skellam/blob/master/README.md Computes the probability mass function (PMF) of the Skellam distribution. It takes a value 'x', and the two Poisson rate parameters 'lambda1' and 'lambda2'. The 'log' argument controls whether the log-density is returned. ```R dskellam(x, lambda1, lambda2 = lambda1, log = FALSE) ``` -------------------------------- ### Simulate Skellam Distribution in R Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This code snippet simulates random variates from the Skellam distribution and compares them to the difference of two Poisson random variables. It sets parameters N, lambda1, and lambda2, then generates Poisson variates X and Y, calculates their difference (XminusY), and generates Skellam variates (Z). ```R N <- 5000 lambda1 <- 1.5 lambda2 <- 0.5 X <- rpois(N, lambda1) Y <- rpois(N, lambda2) XminusY <- X - Y Z <- rskellam(N, lambda1, lambda2) ``` -------------------------------- ### Skellam Distribution Calculations in Python Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This snippet demonstrates how to perform calculations related to the Skellam distribution using Python. It includes functions for probability mass function (PMF) and cumulative distribution function (CDF). ```Python from scipy.stats import skellam # Example usage: mu1 = 5 # Mean of the first Poisson distribution mu2 = 3 # Mean of the second Poisson distribution # Calculate PMF for k=2 k = 2 pmf_value = skellam.pmf(k, mu1, mu2) print(f"PMF at k={k}: {pmf_value}") # Calculate CDF for k=2 cdf_value = skellam.cdf(k, mu1, mu2) print(f"CDF at k={k}: {cdf_value}") ``` -------------------------------- ### Compare Skellam Quantiles with qskellam Function Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This R code snippet compares quantiles derived from simulated Skellam data against those calculated using the `qskellam` function. It generates a sequence of probabilities, computes the quantiles for the simulated data, and plots them against the `qskellam` results. A red reference line (y=x) is added for visual comparison. ```R # Quantile comparison Sprob <- seq(0, 1, by = 1/100) qZ <- quantile(Z, prob = Sprob) plot(qZ, qskellam(Sprob, lambda1, lambda2)) abline(0, 1, col = "#FF000040") ``` -------------------------------- ### Skellam Distribution Calculations in R Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This snippet shows how to implement Skellam distribution calculations in R. It provides functions for the probability mass function (dskellam) and cumulative distribution function (pskellam). ```R library(skellam) # Example usage: mu1 <- 5 # Mean of the first Poisson distribution mu2 <- 3 # Mean of the second Poisson distribution # Calculate PMF for k=2 k <- 2 pmf_value <- dskellam(k, mu1, mu2) print(paste("PMF at k=", k, ": ", pmf_value)) # Calculate CDF for k=2 cdf_value <- pskellam(k, mu1, mu2) print(paste("CDF at k=", k, ": ", cdf_value)) ``` -------------------------------- ### Fit Skellam Regression Model Source: https://github.com/monty-se/skellam/blob/master/README.md Fits a regression model where the response variable is assumed to follow a Skellam distribution. It uses an exponential link function to ensure positive rate parameters and requires the response 'y' and predictor 'x'. ```R skellam.reg(y, x) ``` -------------------------------- ### Compare Skellam Densities with Plots Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This R code generates a plot to compare the empirical density of (X-Y) where X and Y are Poisson samples, with the density of directly simulated Skellam data (Z) and the theoretical Skellam density (dskellam). It uses base R plotting and points functions to overlay these densities and includes a legend for clarity. ```R # Density comparison plot(table(XminusY), xlab = "X - Y", ylab = "", type = "p", pch = 1) points(table(Z), col = "red", type = "p", pch = 3, cex = 2) xseq <- seq(floor(par("usr")[1]), ceiling(par("usr")[2])) points(xseq, N * dskellam(xseq, lambda1, lambda2), col = "blue", pch = 4, cex = 3) legend("topright", pch = c(1, 3, 4), col = c("black", "red", "blue"), legend = c("rpois-rpois", "rskellam", "dskellam")) ``` -------------------------------- ### Compare Skellam Distribution Densities in R Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This R code generates a plot to compare the empirical distribution of the difference between two Poisson random variables (X-Y) against the Skellam distribution. It uses `plot` for the initial comparison, `points` to add the Skellam samples, and overlays the theoretical density function calculated using `dskellam`. A legend is included to identify each plotted element. ```R plot(table(XminusY), xlab = "X - Y", ylab = "", type = "p", pch = 1) points(table(Z), col = "red", type = "p", pch = 3, cex = 2) xseq <- seq(floor(par("usr")[1]), ceiling(par("usr")[2])) points(xseq, N * dskellam(xseq, lambda1, lambda2), col = "blue", pch = 4, cex = 3) legend("topright", pch = c(1, 3, 4), col = c("black", "red", "blue"), legend = c("rpois-rpois", "rskellam", "dskellam")) ``` -------------------------------- ### Update Poisson Parameters and Generate Skellam Data in R Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This R code snippet demonstrates how to update the parameters for Poisson distributions and then generate random variables from the Skellam distribution. It first sets lambda1 to 12 and lambda2 to 8, then generates Poisson random variables X and Y, calculates their difference, and finally generates Skellam random variables Z using the specified lambda values. ```R lambda1 <- 12 lambda2 <- 8 X <- rpois(N, lambda1) Y <- rpois(N, lambda2) XminusY <- X - Y Z <- rskellam(N, lambda1, lambda2) ``` -------------------------------- ### JavaScript: Remove Pandoc Header Attributes Source: https://github.com/monty-se/skellam/blob/master/doc/validate_skellam.html This JavaScript code removes attributes from the first child element of section divs that are identified as headers (h1-h6). This is done to maintain compatibility with older versions of Pandoc (prior to 2.8). ```JavaScript document.addEventListener('DOMContentLoaded', function(e) { var hs = document.querySelectorAll("div.section\[class*='level'] > :first-child"); var i, h, a; for (i = 0; i < hs.length; i++) { h = hs[i]; if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 a = h.attributes; while (a.length > 0) h.removeAttribute(a[0].name); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.