Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Wednesday, October 31, 2018

Vitamin D and Cardiorespiratory Fitness

Here is a study just published showing relationship between cardiorespiratory fitness and vitamin D levels. The study adjusted for various confounders and the relationship was independent of these confounders. The study is cross-sectional and hence the direction of causal effect is difficult to determine. That is, whether greater cardiorespiratory fitness is associated with more time spent outside and hence more sunlight exposure and vitamin D formation or whether vitamin D, through its effects on muscles, nerves, bones, results in higher cardiorespiratory fitness

Saturday, December 27, 2014

Some Thoughts About Clinical Research

Clinical research requires a wide range of skills. These skill include the ability to work with a wide range of people, to lead teams with people from wide and vastly different backgrounds, to design appropriate studies, to ask right questions, to understand research methods specific to the study question, to develop in-depth content expertise in the area of research focus, to get funding for research projects, to present study results at national meetings, to write manuscripts for publication in peer-review journals, and so on and so forth.

A fundamental skill for a researcher is the ability to knit together the conceptual framework for a study (theory) with appropriate measurement, with the result either supporting or opposing the conceptual framework. The theory should be based on the most current state of knowledge, the data collected should have the ability to test the theory, the statistical models should reflect both the conceptual structure hypothesized to have given rise to the data and the nature of collected data, and the inferences should be based on the data and the tested statistical models. This process is not linear, rather it is a loop in which theoretical aspects inform the collection of data and results of the data analyses help in refining the theory, which generates more testable hypothesis, additional data collection, and so on.

Most research is probabilistic, as opposed to deterministic. In other words, the results we obtain are not always certain; we have to include uncertainty in our analyses and expect some uncertainty in our results and inferences. Thus, we have to accept that our results are unlikely to be laws governing the system we plan to study and more likely to be an approximation of what we expect to find in the real world, with some uncertainty. There are many reasons and sources of this uncertainty some of which can be addressed while others may still be there despite our best attempts.

A researcher should determine whether the interest of research is to build inferences at population level or at the level of individuals unit (often a patient in clinical research). The study design, data collection and analysis, and the inferences may be quite different depending on what is the object of our interest. While we study individuals, our results usually address inferences at population level. In general, it is much easier to predict about the response at a population level, that is on an average, individuals with higher body mass index (say >30) will have higher blood glucose than (say) 126mg/dL. However, it is much difficult to predict with certainty how likely a particular individual with a BMI>30 is to have higher blood glucose level than 126 mg/dL. For a predictor to work well at an individual level, among other things effect size needs to be quite large.

Another important concept is that of causality. While we often have a conceptual model in our mind that A is caused by B, it may be quite difficult to prove except perhaps in a clinical trial setting. There are several factors that can increase the likelihood that the direction of cause and effect in our conceptual model is correct, such as temporality and biological plausibility.  However, often there remains a possibility that B is in fact caused by A or that some other unknown (or unmeasured) factor, C, may be responsible for both A and B. Hence, we often claim an association or correlation between A and B and not causality.

Friday, December 19, 2014

Starting to work with R

There may be some who have just started working with R after someone convinced them that R is the way to go. For those souls, it may be difficult to get started quickly. Below are some of the steps to use to start working with R

Step 1: Go to the CRAN webpage and download the version of R that is appropriate for your operating system - http://cran.r-project.org/

Step 2: Install R

Step 3: Download a GUI for R – While R comes with a GUI, other GUIs are much better. My favorite is RStudio, To download RStudio, go to RStudio website and download the version that is appropriate for your operating system - http://www.rstudio.com/products/rstudio/download/

Step 4: Install RStudio (or a GUI of your choice).

Step 5: Start using RStudio (or GUI of your choice)

That’s it – Good luck!

Monday, October 07, 2013

Wednesday, July 31, 2013

Extracting phenotype type by genotype using GenABEL

GenABEL is an excellent R package for GWAS studies. It uses special data structure to efficiently store data. The data structure is quite useful and results in remarkable time saving when running GWAS, it does have some limitations. For example, often in GWAS studies one need to know phenotype distribution across genotype of some variant but I couldn’t find a straightforward way of looking at phenotype distribution across genotypes (there may be a better way of doing it but I couldn’t find it)

To get phenotypic information across genotypes I used the following approach (assuming that data is in an object called ‘data’

1. Abstract phenotypic information
pheno<- phdata(data)
The returned object is a dataframe and can be confirmed with class(pheno) command

2. Abstract SNP data
snps <- as.character(data[, c("SNP1", "SNP2", "SNP3")])
You can change as.character in the line above with as.numeric if you want to get genotype information in 0,1,2 format.
The returned object is a matrix with row numbers as subject ID. Thus we need to do two things with this matrix. First we have to convert it into a dataframe and then we have to convert rownames into a column of id

3. Convert matrix 'snps' into a dataframe with row names as an additional column
snps.df<-data.frame(as.numeric(rownames(snps)),snps)
colnames(snps.df)[1]="id"
                          ### Change the column name to 'id'
snp.data <- merge(pheno, snps.df, by="id")  

Now you have a dataframe with phenotype data and SNPs genotype data

Sunday, June 30, 2013

Downloading and Merging NHANES datasets in R

The National Health and Nutrition Examination Survey (NHANES) is a program of studies designed to assess the health and nutritional status of adults and children in the United States. The survey is unique in that it combines interviews and physical examinations. The data files for more recent surveys are given in SAS Export format. To read these files in to R, one needs to use functions in the foreign package. If you don’t have this package, you may need to install it first. In the first step, we download these files and then in the second step we import these files to R.

# load foreign package (Converts data files into R)
require(foreign)    

# Set your working directory
setwd( "<YOUR WORKING DIRECTORY>")

### Download demographics file of NHANES 2005-2006 dataset
download.file(
ftp://ftp.cdc.gov/pub/Health_Statistics/nchs/nhanes/2005-2006/DEMO_D.XPT,
"Demo0506.xpt", mode='wb')

###Read downloaded file
Demo56<-read.xport("Demo0506.xpt")

### Download Blood pressure file of NHANES 2005-2006 dataset
download.file(
ftp://ftp.cdc.gov/pub/Health_Statistics/nchs/nhanes/2005-2006/BPX_D.XPT,
"BP0506.xpt", mode='wb')

### Read downloaded file
BP56<-read.xport("BP0506.xpt")

### Merge the two files
N_05_06 <- merge(Demo56, BP56, all=T)

You can download several files and then merge them together to get your dataset.