/usr/lib/R/site-library/S4Vectors/doc/RleTricks.Rnw is in r-bioc-s4vectors 0.16.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | \documentclass{article}
% \VignetteIndexEntry{Rle Tips and Tricks}
% \VignetteDepends{}
% \VignetteKeywords{Rle}
% \VignettePackage{S4Vectors}
\usepackage{times}
\usepackage{hyperref}
\textwidth=6.5in
\textheight=8.5in
% \parskip=.3cm
\oddsidemargin=-.1in
\evensidemargin=-.1in
\headheight=-.3in
\newcommand{\Rfunction}[1]{{\texttt{#1}}}
\newcommand{\Robject}[1]{{\texttt{#1}}}
\newcommand{\Rpackage}[1]{{\textit{#1}}}
\newcommand{\Rmethod}[1]{{\texttt{#1}}}
\newcommand{\Rfunarg}[1]{{\texttt{#1}}}
\newcommand{\Rclass}[1]{{\textit{#1}}}
\newcommand{\Rcode}[1]{{\texttt{#1}}}
\newcommand{\software}[1]{\textsf{#1}}
\newcommand{\R}{\software{R}}
\title{Rle Tips and Tricks}
\author{Patrick Aboyoun}
\date{\today}
\begin{document}
\maketitle
<<options,echo=FALSE>>=
options(width=60)
@
<<Rle-rollmean>>=
rollmeanRle <- function (x, k)
{
n <- length(x)
cumsum(c(Rle(sum(window(x, 1, k))), window(x, k + 1, n) - window(x, 1, n - k))) / k
}
@
<<Rle-rollvar>>=
rollvarRle <- function(x, k)
{
n <- length(x)
means <- rollmeanRle(x, k)
nextMean <- window(means, 2, n - k + 1)
cumsum(c(Rle(sum((window(x, 1, k) - means[1])^2)),
k * diff(means)^2 -
(window(x, 1, n - k) - nextMean)^2 +
(window(x, k + 1, n) - nextMean)^2)) / (k - 1)
}
@
<<Rle-rollcov>>=
rollcovRle <- function(x, y, k)
{
n <- length(x)
meanX <- rollmeanRle(x, k)
meanY <- rollmeanRle(y, k)
nextMeanX <- window(meanX, 2, n - k + 1)
nextMeanY <- window(meanY, 2, n - k + 1)
cumsum(c(Rle(sum((window(x, 1, k) - meanX[1]) * (window(y, 1, k) - meanY[1]))),
k * diff(meanX) * diff(meanY) -
(window(x, 1, n - k) - nextMeanX) * (window(y, 1, n - k) - nextMeanY) +
(window(x, k + 1, n) - nextMeanX) * (window(y, k + 1, n) - nextMeanY))) / (k - 1)
}
@
<<Rle-rollsd>>=
rollsdRle <- function(x, k)
{
sqrt(rollvarRle(x, k))
}
@
<<Rle-rollcor>>=
rollcorRle <- function(x, y, k)
{
rollcovRle(x, y, k) / (rollsdRle(x, k) * rollsdRle(y, k))
}
@
\end{document}
|