sample.Meth: Sample Meth object with replacement

Description Usage Arguments Value Author(s) Examples

View source: R/sample.Meth.r

Description

Sample a Meth object with replacement. If how=="random", a random sample of the rows are sampled, the existing values of meth, item and y are kept but new replicate numbers are generated. If how=="linked", a random sample of the linked observations (i.e. observations with identical item and repl values) are sampled with replacement and replicate numbers are kept. If how=="item", items are sampled with replacement, and their observations are included the sampled numner of times.

Usage

1
2
3
4
5
sample.Meth(
  x,
  how = "random",
  N = if (how == "items") nlevels(x$item) else nrow(x)
)

Arguments

x

A Meth object.

how

Character. What sampling strategy should be used, one of "random", "linked" or "item". Only the first letter is significant. See details for explanation.

N

How many observations should be sampled?

Value

A meth object

Author(s)

Bendix Carstensen, bendix.carstensen@regionh.dk

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
29
30
31
32
data(fat)
# Different ways of selecting columns and generating replicate numbers
Sub1 <- Meth(fat,meth=2,item=1,repl=3,y=4,print=TRUE)
Sub2 <- Meth(fat,2,1,3,4,print=TRUE)
Sub3 <- Meth(fat,meth="Obs",item="Id",repl="Rep",y="Sub",print=TRUE)
summary( Sub3 )
plot( Sub3 )

# Use observation in different columns as methods
data( CardOutput )
head( CardOutput )
sv <- Meth( CardOutput, y=c("Svo2","Scvo2") )
# Note that replicates are generated if a non-unique item-id is used
sv <- Meth( CardOutput, y=c("Svo2","Scvo2"), item="Age" )
str( sv )
# A summary is not created if the the first argument (data=) is not used:
sv <- Meth( y=CardOutput[,c("Svo2","Scvo2")], item=CardOutput$VO2 )
summary(sv)

# Sample items
ssv <- sample.Meth( sv, how="item", N=8 )

# More than two methods
data( sbp )
plot( Meth( sbp ) )
# Creating non-unique replicate numbers per (meth,item) creates a warning:
data( hba1c )
hb1  <- with( hba1c,
              Meth( meth=dev, item=item, repl=d.ana-d.samp, y=y, print=TRUE ) )
hb2  <- with( subset(hba1c,type=="Cap"),
              Meth( meth=dev, item=item, repl=d.ana-d.samp, y=y, print=TRUE ) )
  

MethComp documentation built on Jan. 20, 2020, 1:12 a.m.