###################
## First Example ##
## A highly artificial example with not enough subjects to be run;
## however, it demonstrates how to put data in it.
## We have two cnvs here, cnv1 and cnv2.
## The data is just completely random.
set.seed(13)
x <- data.frame( pid = c(1,1,1,1,1),
id = c(1,2,3,4,5),
idfath = c(4,4,4,0,0),
idmoth = c(5,5,5,0,0),
sex = c(1,2,1,1,2),
AffectionStatus = c(1,0,0,1,0),
cnv1.1 = runif(5),
cnv1.2 = runif(5),
cnv1.3 = runif(5),
cnv2.1 = runif(5),
cnv2.2 = runif(5),
cnv2.3 = runif(5) )
x
myCPed <- as.cped( x ) # Mark it with the class 'cped'
myCPed
if (FALSE) {
####################
## Second Example ##
## Again, a completely random dataset.
## Here we go through an analysis of it.
## However, see pbat.m for many more details on all of the options.
## Create a completely random dataset with one cnv.
set.seed(13)
NUMTRIOS <- 500
## The data is completely random, it does not really make any sense.
cped <- as.cped(data.frame(
pid = kronecker(1:NUMTRIOS, rep(1,3)),
id = rep(1:3, NUMTRIOS),
idfath = rep(c(0,0,1), NUMTRIOS),
idmoth = rep(c(0,0,2), NUMTRIOS),
sex = rep(c(2,1,1), NUMTRIOS),
AffectionStatus = rep(c(0,0,2), NUMTRIOS),
cnv1.1 = runif(3*NUMTRIOS),
cnv1.2 = runif(3*NUMTRIOS),
cnv1.3 = runif(3*NUMTRIOS)))
## Print out part of the dataset
print(head(cped))
## Command line run
pbat.work() ## Makes the intermediate files go in ./pbatRwork directory
## - Analyzing the first intensity
res1 <- pbat.m(AffectionStatus ~ NONE, ped=cped, phe=NULL, fbat="gee",
cnv.intensity=1, cnv.intensity.num=3, offset="none")
pbat.clean(res1, all.output=TRUE) ## Removes all intermediate files
## - Analyzing the second intensity
res2 <- pbat.m(AffectionStatus ~ NONE, ped=cped, phe=NULL, fbat="gee",
cnv.intensity=2, cnv.intensity.num=3, offset="none")
pbat.clean(res2, all.output=TRUE)
## - Analyzing the third intensity
res3 <- pbat.m(AffectionStatus ~ NONE, ped=cped, phe=NULL, fbat="gee",
cnv.intensity=3, cnv.intensity.num=3, offset="none")
pbat.clean(res3, all.output=TRUE)
pbat.unwork() ## Close up work (head to original working directory)
## Print all of the results
print(res1$results)
print(res2$results)
print(res3$results)
## Or put all the results together and write to file
res1$results <- rbind(res1$results, res2$results, res3$results)
write.pbat(res1, "cpedResults.csv")
## Otherwise, we could write the data to disk,
## and run with the GUI interface
## Write the data to disk:
write.cped("cped.cped", cped)
}
Run the code above in your browser using DataCamp Workspace