Last data update: 2014.03.03

R: Class 'NullModel'
NullModel-classR Documentation

Class NullModel

Description

S4 class for storing null models for later usage with the assocTest method

Objects

Objects of this class are created by calling nullModel.

Slots

The following slots are defined for NullModel objects:

type:

type of model

residuals:

residuals of linear model; for type “bernoulli”, this is simply the trait vector (see nullModel-methods for details)

model.matrix:

model matrix of the (generalized) linear model trained for the covariates (if any)

inv.matrix:

pre-computed inverse of some matrix needed for computing the null distribution; only used for types “logistic” and “linear”

P0sqrt:

pre-computed square root of matrix P_0 (see Subsections 9.1 and 9.5 of the package vignette); needed for computing the null distribution in case the small sample correction is used for a logistic model; computed only if nullModel is called with adjExact=TRUE.

coefficients:

coefficients of (generalized) linear model trained for the covariates (if any)

na.omit:

indices of samples omitted from (generalized) linear model because of missing values in target or covariates

n.cases:

for binary traits (types “logistic” and “bernoulli”), the number of cases, i.e. the number of 1's in the trait vector

variance:

for continuous traits (type “linear”), this is a single numeric value with the variance of residuals of the linear model; for logistic models with binary traits (type “logistic”), this is a vector with variances of the per-sample Bernoulli distributions; for later use of the exact mixture-of-Bernoulli test (type “bernoulli”), this is the variance of the Bernoulli distribution

prob:

for logistic models with binary traits (type “logistic”), this is a vector with probabilities of the per-sample Bernoulli distributions; for later use of the exact mixture-of-Bernoulli test (type “bernoulli”), this is the probability of the Bernoulli distribution

type.resampling:

which resampling algorithm was used

res.resampling:

matrix with residuals sampled under the null hypothesis (if any)

res.resampling.adj:

matrix with residuals sampled under the null hypothesis for the purpose of higher moment correction (if any; only used for logistic models with small sample correction)

call:

the matched call with which the object was created

Details

This class serves as the general interface for storing the necessary phenotype information for a later association test. Objects of this class should only be created by the nullModel function. Direct modification of object slots is strongly discouraged!

Methods

show

signature(object="NullModel"): displays basic information about the null model, such as, the type of the model and the numbers of covariates.

Accessors

residuals

signature(object="NullModel"): returns the residuals slot.

names

signature(object="NullModel"): returns the names of samples in the null model.

coefficients

signature(object="NullModel"): returns the coefficients slot.

length

signature(x="NullModel"): returns the number of samples that was used to train the null model.

Subsetting

For a NullModel object x and an index vector i that is a permutation of 1:length(x), x[i] returns a new NullModel object in which the samples have been rearranged according to the permutation i. This is meant for applications in which the order of the samples in a subsequent association test is different from the order of the samples when the null model was trained/created.

Author(s)

Ulrich Bodenhofer bodenhofer@bioinf.jku.at

References

http://www.bioinf.jku.at/software/podkat

See Also

nullModel

Examples

## read phenotype data from CSV file (continuous trait + covariates)
phenoFile <- system.file("examples/example1lin.csv", package="podkat")
pheno <-read.table(phenoFile, header=TRUE, sep=",")

## train null model with all covariates in data frame 'pheno'
model <- nullModel(y ~ ., pheno)
model
length(model)
residuals(model)

## read phenotype data from CSV file (binary trait + covariates)
phenoFile <- system.file("examples/example1log.csv", package="podkat")
pheno <-read.table(phenoFile, header=TRUE, sep=",")

## train null model with all covariates in data frame 'pheno'
model <- nullModel(y ~ ., pheno)
model
length(model)
residuals(model)

## "train" simple Bernoulli model on a subset of 100 samples
model <- nullModel(y ~ 0, pheno[1:100, ])
model
length(model)
residuals(model)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(podkat)
Loading required package: Rsamtools
Loading required package: GenomeInfoDb
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: GenomicRanges
Loading required package: Biostrings
Loading required package: XVector
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/podkat/NullModel-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: NullModel-class
> ### Title: Class 'NullModel'
> ### Aliases: NullModel-class class:NullModel NullModel
> ###   residuals,NullModel-method names,NullModel-method
> ###   show,NullModel-method length,NullModel-method
> ###   coefficients,NullModel-method
> ###   [,NullModel,index,missing,missing-method
> ### Keywords: classes
> 
> ### ** Examples
> 
> ## read phenotype data from CSV file (continuous trait + covariates)
> phenoFile <- system.file("examples/example1lin.csv", package="podkat")
> pheno <-read.table(phenoFile, header=TRUE, sep=",")
> 
> ## train null model with all covariates in data frame 'pheno'
> model <- nullModel(y ~ ., pheno)
> model
Linear model:
	Number of covariates: 2 (+ intercept)
	Number of samples: 200
	Variance of residuals: 1.541756 
	No resampling
> length(model)
[1] 200
> residuals(model)
         S1          S2          S3          S4          S5          S6 
 0.39014181 -1.39300779  1.85400931 -1.61205229  1.33408378 -0.38730241 
         S7          S8          S9         S10         S11         S12 
-1.14282631 -0.96029056 -1.51834011 -0.54827192 -1.01348240 -1.55758254 
        S13         S14         S15         S16         S17         S18 
 1.53464252  1.07833976  1.60811676  0.19654847 -2.06523017  1.90660882 
        S19         S20         S21         S22         S23         S24 
-0.72476781  2.37107646 -0.55910036  1.20271608 -0.62130314  0.55283759 
        S25         S26         S27         S28         S29         S30 
 0.84414011  0.55622025  0.35151060  1.33753425 -2.19567386  0.37039083 
        S31         S32         S33         S34         S35         S36 
-0.68344743  0.44499220 -0.10213178 -0.62772595 -2.48237393 -1.70344322 
        S37         S38         S39         S40         S41         S42 
 0.19996009  0.48322856  0.61151372  0.17842953  0.94216971  3.76197892 
        S43         S44         S45         S46         S47         S48 
 2.63255560 -0.32488929  0.18098393 -0.44430856  0.14643080  1.06171198 
        S49         S50         S51         S52         S53         S54 
 0.87117521  0.15183686  0.19655101 -2.74400944 -1.94529193  0.40266285 
        S55         S56         S57         S58         S59         S60 
-1.75012570 -0.23124708  1.05526112  0.01422120 -1.40387189 -0.19500011 
        S61         S62         S63         S64         S65         S66 
-2.43082308  0.30497638 -0.22147083 -0.45480724 -0.79988329  1.70626630 
        S67         S68         S69         S70         S71         S72 
-0.74353686  0.80805709 -0.87785569  0.97984313 -0.61811470 -0.83171062 
        S73         S74         S75         S76         S77         S78 
 0.37480549  0.44021835  0.81507998  1.15273351  1.37346569  1.16607400 
        S79         S80         S81         S82         S83         S84 
 0.90283624  0.06793032  0.58744320  0.17760469 -1.64128972  1.41244134 
        S85         S86         S87         S88         S89         S90 
-1.48552498 -0.19755143  0.27469699 -0.86674652  2.09286110 -0.40525504 
        S91         S92         S93         S94         S95         S96 
 1.70646964  0.72383468  2.20365021 -1.28028070 -0.95019213 -0.85546495 
        S97         S98         S99        S100        S101        S102 
 0.79538547  0.05156775  1.37717389 -2.01649232  0.50503219  0.80842013 
       S103        S104        S105        S106        S107        S108 
 2.32195025 -1.51964043 -1.04327597  0.78113904 -0.03700412 -3.06370053 
       S109        S110        S111        S112        S113        S114 
 2.06301631 -1.78171375 -1.07629035 -0.30388307  2.43209814 -0.47550116 
       S115        S116        S117        S118        S119        S120 
 0.09150307  0.46828691  0.79631416  0.58181695 -0.23379269 -0.87663031 
       S121        S122        S123        S124        S125        S126 
 1.84642167 -1.79884464 -2.03370937  0.42806331 -1.09712422 -0.35465270 
       S127        S128        S129        S130        S131        S132 
-0.42796367 -0.52457553  2.39742586  0.79145751 -1.69423801  1.22795810 
       S133        S134        S135        S136        S137        S138 
 3.38083228  0.42832027  1.33024311  0.03614366 -0.03307896  0.19840447 
       S139        S140        S141        S142        S143        S144 
-0.82528056  0.47121330 -1.05624364 -0.30265278 -0.09305519 -0.76627245 
       S145        S146        S147        S148        S149        S150 
-0.15996942 -1.11034339 -0.13947800  0.04442201  1.31156104  0.05773790 
       S151        S152        S153        S154        S155        S156 
-1.51706512 -0.48340823 -1.28372951  1.74455205  0.18559217  0.53506101 
       S157        S158        S159        S160        S161        S162 
-0.31675682  1.74486201 -0.73952458  1.60615030 -2.43569022 -0.78778190 
       S163        S164        S165        S166        S167        S168 
-0.85470255 -0.60724082 -2.13869012 -2.23853120 -0.06356836 -0.80209005 
       S169        S170        S171        S172        S173        S174 
-0.42275366 -0.27730446  0.21477973 -0.99495669 -0.13693821  1.10726126 
       S175        S176        S177        S178        S179        S180 
-0.75809829  3.25898566  0.49555921 -1.63844984 -0.60092204  1.20955023 
       S181        S182        S183        S184        S185        S186 
 0.52329060  0.40950944  0.06245806  1.15603490  1.48270760  0.20813829 
       S187        S188        S189        S190        S191        S192 
-2.41123531 -1.10379879  1.36808303 -1.12515020  0.53708718  0.62900469 
       S193        S194        S195        S196        S197        S198 
-0.10175562  0.81119248 -0.76371545  0.43234109 -0.57459961 -2.09055752 
       S199        S200 
 0.10457684  0.76547256 
> 
> ## read phenotype data from CSV file (binary trait + covariates)
> phenoFile <- system.file("examples/example1log.csv", package="podkat")
> pheno <-read.table(phenoFile, header=TRUE, sep=",")
> 
> ## train null model with all covariates in data frame 'pheno'
> model <- nullModel(y ~ ., pheno)
small sample correction applied
> model
Logistic model:
	Number of covariates: 2 (+ intercept)
	Number of samples: 200
	Number of positives (cases): 10 
	No resampling
	Adjustment of higher moments: 10000 repeats (bootstrap)
> length(model)
[1] 200
> residuals(model)
          S1           S2           S3           S4           S5           S6 
-0.045393031 -0.167930303 -0.057814107 -0.003955454 -0.027595389 -0.105811682 
          S7           S8           S9          S10          S11          S12 
-0.019988648 -0.034810400 -0.033473174 -0.015009105 -0.075179466 -0.024394999 
         S13          S14          S15          S16          S17          S18 
-0.015877701 -0.068399381 -0.062456017 -0.013593386 -0.073614568 -0.019517811 
         S19          S20          S21          S22          S23          S24 
-0.061584208 -0.023647400 -0.054074282 -0.181271604 -0.068055553  0.974284963 
         S25          S26          S27          S28          S29          S30 
-0.145329437 -0.002767212 -0.012294228 -0.070628884 -0.030155590 -0.060535354 
         S31          S32          S33          S34          S35          S36 
-0.037216658 -0.108211542 -0.036040608 -0.041366475 -0.047501475 -0.059594706 
         S37          S38          S39          S40          S41          S42 
-0.023044785 -0.009809251 -0.041996919 -0.076698374 -0.047202859 -0.010578202 
         S43          S44          S45          S46          S47          S48 
-0.018284108 -0.063786098 -0.019673563 -0.012044180 -0.007368971 -0.011730486 
         S49          S50          S51          S52          S53          S54 
-0.067056953 -0.047695312 -0.044867274 -0.034636363 -0.010994595 -0.037609532 
         S55          S56          S57          S58          S59          S60 
-0.088949801 -0.014599940 -0.016529995 -0.072410744 -0.074775556 -0.033188920 
         S61          S62          S63          S64          S65          S66 
-0.061430424 -0.120540929  0.761479301 -0.022917240 -0.051051866 -0.041706933 
         S67          S68          S69          S70          S71          S72 
-0.006453105 -0.041027806 -0.030991764 -0.023044875 -0.006887752 -0.011297784 
         S73          S74          S75          S76          S77          S78 
-0.028909237 -0.021715294 -0.049836443 -0.046737449 -0.055060887 -0.018219571 
         S79          S80          S81          S82          S83          S84 
-0.032564091  0.956459436 -0.111841011 -0.045706689 -0.050893870  0.859442253 
         S85          S86          S87          S88          S89          S90 
-0.015956008 -0.231147686 -0.024650699 -0.016316900 -0.026612112 -0.048460284 
         S91          S92          S93          S94          S95          S96 
-0.053143941 -0.107022942 -0.037599987 -0.063419966 -0.046021957 -0.019995950 
         S97          S98          S99         S100         S101         S102 
-0.042263649 -0.014369391 -0.046402844 -0.008416013 -0.017703781 -0.005619499 
        S103         S104         S105         S106         S107         S108 
-0.045175634 -0.056641195 -0.116579909 -0.108218214 -0.037370474 -0.078280479 
        S109         S110         S111         S112         S113         S114 
-0.132643458 -0.018078647 -0.021009766 -0.039629281 -0.016528544 -0.052219716 
        S115         S116         S117         S118         S119         S120 
-0.006765629 -0.009588772 -0.058053275 -0.051906034 -0.028301556 -0.059163220 
        S121         S122         S123         S124         S125         S126 
-0.049515752 -0.025901288 -0.184056705 -0.076222485 -0.209815897 -0.081767302 
        S127         S128         S129         S130         S131         S132 
 0.912128335 -0.008290177 -0.008097736 -0.092634082 -0.039561192 -0.041385348 
        S133         S134         S135         S136         S137         S138 
-0.018010232 -0.033250010 -0.023171433 -0.028754265 -0.029858263 -0.024295099 
        S139         S140         S141         S142         S143         S144 
-0.014854808  0.919850561 -0.006812453 -0.002898144 -0.027013842 -0.008176772 
        S145         S146         S147         S148         S149         S150 
-0.043938984 -0.012700882 -0.024753712 -0.033925675 -0.033346675 -0.003235956 
        S151         S152         S153         S154         S155         S156 
-0.148707122 -0.179165800 -0.089788756 -0.042816950 -0.009812559  0.919239709 
        S157         S158         S159         S160         S161         S162 
-0.151319500 -0.015716955 -0.003314139 -0.037802951 -0.018657507 -0.022116279 
        S163         S164         S165         S166         S167         S168 
-0.018432145 -0.074466331 -0.093264289 -0.010903914 -0.206425530 -0.043651379 
        S169         S170         S171         S172         S173         S174 
-0.089984962 -0.044163947 -0.041576509 -0.079298365 -0.069332269 -0.088450214 
        S175         S176         S177         S178         S179         S180 
-0.036839484  0.977610250 -0.095886768 -0.013925731 -0.048070097 -0.059416539 
        S181         S182         S183         S184         S185         S186 
-0.055210518 -0.050896853 -0.023679327 -0.129357090  0.848714795 -0.019374720 
        S187         S188         S189         S190         S191         S192 
-0.040122393 -0.038717520 -0.013846786 -0.007357227 -0.023353975 -0.050335106 
        S193         S194         S195         S196         S197         S198 
-0.060132648 -0.013423302  0.964332121 -0.023076775 -0.030909077 -0.004503077 
        S199         S200 
-0.034675568 -0.024282568 
> 
> ## "train" simple Bernoulli model on a subset of 100 samples
> model <- nullModel(y ~ 0, pheno[1:100, ])
> model
Simple Bernoulli model:
	Raw phenotypes (no covariates, no intercept)
	Number of samples: 100
	Number of positives (cases): 4 
	No resampling
> length(model)
[1] 100
> residuals(model)
  S1   S2   S3   S4   S5   S6   S7   S8   S9  S10  S11  S12  S13  S14  S15  S16 
   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0 
 S17  S18  S19  S20  S21  S22  S23  S24  S25  S26  S27  S28  S29  S30  S31  S32 
   0    0    0    0    0    0    0    1    0    0    0    0    0    0    0    0 
 S33  S34  S35  S36  S37  S38  S39  S40  S41  S42  S43  S44  S45  S46  S47  S48 
   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0 
 S49  S50  S51  S52  S53  S54  S55  S56  S57  S58  S59  S60  S61  S62  S63  S64 
   0    0    0    0    0    0    0    0    0    0    0    0    0    0    1    0 
 S65  S66  S67  S68  S69  S70  S71  S72  S73  S74  S75  S76  S77  S78  S79  S80 
   0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    1 
 S81  S82  S83  S84  S85  S86  S87  S88  S89  S90  S91  S92  S93  S94  S95  S96 
   0    0    0    1    0    0    0    0    0    0    0    0    0    0    0    0 
 S97  S98  S99 S100 
   0    0    0    0 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>