vlyl: vlyl

Description Usage Arguments Details Value Author(s) Examples

View source: R/functions.R

Description

Return co-ordinates of L-regions for local cFDR using KDEs. Automatically includes an estimate of Pr(H0|Q<q).

Usage

1
2
3
vlyl(p, q, indices = NULL, at = NULL, mode = 0, fold = NULL,
  p_threshold = 0, nt = 5000, nv = 1000, scale = c("p", "z"),
  closed = T, bw = 1, ...)

Arguments

p

principal p-values

q

conditional p-values

indices

compute v(L) at indices of points. Overrides parameter at if set.

at

cfdr cutoff/cutoffs. Defaults to null

mode

set to 0 to leave all of 'indices' in, 1 (NOT CURRENTLY SUPPORTED) to remove each index only when computing L at that point, 2 to remove all of 'indices' from p,q

fold

If mode=2, only compute L-curves using points not in 'fold'.

p_threshold

if H0 is to be rejected automatically whenever p<p_threshold, include this in all regions L

nt

number of test points in x-direction, default 5000

nv

resolution for constructing L-curves, default 1000

scale

return curves on the p- or z- plane. Y values are equally spaced on the z-plane.

closed

determines whether curves are closed polygons encircling regions L (closed=T), or lines indicating the rightmost border of regions L

...

other parameters passed to function kde2d. Can be used to set a non-Gaussian kernel.

adj

adjust cFDR values and hence curves L using estimate of Pr(H0|Pj<pj)

Details

Estimates empirical distribution of (P,Q) by fitting a kernel density estimate to observed values.

Value

list containing elements x, y. Assuming n curves are calculated and closed=T (where n=length(indices) or length(at)), x is a matrix of dimension n x (4+nv), y ix a vector of length (4+nv).

Author(s)

James Liley

Examples

 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
# Generate standardised simulated dataset
set.seed(1); n=10000; n1p=100; n1pq=100; n1q=100
zp=c(rnorm(n1p,sd=3), rnorm(n1q,sd=1),rnorm(n1pq,sd=3), rnorm(n-n1p-n1q-n1pq,sd=1))
zq=c(rnorm(n1p,sd=1), rnorm(n1q,sd=3),rnorm(n1pq,sd=3), rnorm(n-n1p-n1q-n1pq,sd=1))
p=2*pnorm(-abs(zp)); q=2*pnorm(-abs(zq))
fold_id=(1:n) %% 3

# estimate parameters of underying dataset
fit_pars=fit.4g(cbind(zp,zq))$pars

# estimate parameters of underying dataset, removing fold 1
fit_pars_fold23=fit.4g(cbind(zp[which(fold_id!=1)],zq[which(fold_id!=1)]))$pars


# points to generate L-regions for
example_indices=c(4262, 268,83,8203)

par(mfrow=c(1,2))

v=vlx(p,q,pars=fit_pars,indices=example_indices); 
plot(p,q,cex=0.5,col="gray",xlim=c(0,0.001),ylim=c(0,1), main="All points in"); 
for (i in 1:length(example_indices)) lines(v$x[i,],v$y); 
for (i in 1:length(example_indices)) points(p[example_indices[i]],q[example_indices[i]],pch=16,col="blue")

v2=vlx(p,q,pars=fit_pars_fold23,indices=example_indices); 
plot(p,q,cex=0.5,col="gray",xlim=c(0,0.001),ylim=c(0,1), main="Fold removed"); 
for (i in 1:length(example_indices)) lines(v2$x[i,],v2$y); 
for (i in 1:length(example_indices)) points(p[example_indices[i]],q[example_indices[i]],pch=16,col="blue")

jamesliley/cfdr documentation built on July 31, 2020, 9:42 a.m.