xCorrelation | R Documentation

## Function to calculate and visualise correlation

### Description

`xCorrelation` is supposed to calculate and visualise correlation between a data frame and a named vector (or a list of named vectors).

### Usage

    xCorrelation(df, list_vec, method = c("pearson", "spearman"),
    p.type = c("nominal", "empirical"), seed = 825, nperm = 2000,
    p.adjust.method = c("BH", "BY", "bonferroni", "holm", "hochberg",
    "hommel"),
    plot = FALSE, plot.smooth = c(NA, "lm", "loess"))

### Arguments

`df` | a data frame with two columns ('name' and 'value')
`list_vec` | a named vector containing numeric values. Alternatively it can be a list of named vectors
`method` | the method used to calcualte correlation. It can be 'pearson' for Pearson's correlation or 'spearman' for Spearman rank correlation
`p.type` | the type of the p-value calcualted. It can be 'nominal' for nominal p-value or 'empirical' for empirical p-value
`seed` | an integer specifying the seed
`nperm` | the number of random permutations
`p.adjust.method` | the method used to adjust p-values. It can be one of "BH", "BY", "bonferroni", "holm", "hochberg" and "hommel". The first two methods "BH" (widely used) and "BY" control the false discovery rate (FDR: the expected proportion of false discoveries amongst the rejected hypotheses); the last four methods "bonferroni", "holm", "hochberg" and "hommel" are designed to give strong control of the family-wise error rate (FWER). Notes: FDR is a less stringent condition than FWER
`plot` | logical to indicate whether scatter plot is drawn
`plot.smooth` | the smooth method for the scatter plot. It can be NA (depending on correlation type), "lm" for the linear line or 'loess' for the loess curve

### Value

a list with three componets:

- `df_summary`: a data frame of n x 5, where n is the number of named vectors, and the 5 columns are "name", "num" (i.e. number of data points used for calculation), "cor" (i.e. correlation), "pval" (i.e. p-value), "fdr"

- `ls_gp_curve`: NULL if the plot is not drawn; otherwise, a list of 'ggplot' objects for scatter plot together with an estimated curve

- `ls_gp_pdf`: NULL if the plot is not drawn; otherwise, a list of 'ggplot' objects for pdf plot for null distribution of correlation together with a vertical line for observed correlation

### Note

none

### See Also

`xCorrelation`

### Examples

    ## Not run:
    # Load the library
    library(XGR)

    ## End(Not run)

    RData.location <- "http://galahad.well.ox.ac.uk/bigdata_dev"
    ## Not run:
    # a) provide the seed nodes/genes with the weight info
    ## load ImmunoBase
    ImmunoBase <- xRDataLoader(RData.customised='ImmunoBase',
    RData.location=RData.location)
    ## get genes within 500kb away from AS GWAS lead SNPs
    seeds.genes <- ImmunoBase$AS$genes_variants
    ## seeds weighted according to distance away from lead SNPs
    data <- 1- seeds.genes/500000

    # b) prepare a data frame
    df <- data.frame(name=names(data), value=data, stringsAsFactors=FALSE)

    # c) do correlation
    ls_res <- xCorrelation(df, data, method="pearson", p.type="empirical",
    nperm=2000, plot=TRUE)

    ## End(Not run)