With cancer accounting for approximately 1 in 4 US deaths it is important to know a good resource for cancer-related statistics. Luck for us, the 2014 Cancer Facts and Figures has just been released by the American Cancer Society. This is an excellent resource on the distribution of cancer by age, sex, race, type, and geographic location in the United States. It includes cancer specific information on new cases, deaths, signs and symptoms, risk factors, prevention, early detection, treatment, and survival. This is a wonderful, up-to-date resource for getting cancer-related estimates on prevalence, incidence, mortality, and survival in the US as well as look at trends and statistics from years past. In addition, the website includes a wealth of other resources including tables, slides, and figures that are handy visual aids for presentations.
A repository of programs, scripts, and tips essential to
genetic epidemiology, statistical genetics, and bioinformatics
Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.
Showing posts with label statistics. Show all posts
Showing posts with label statistics. Show all posts
Tuesday, February 18, 2014
Monday, January 27, 2014
Produce SAS Proc Freq Output in R
I have never been a huge fan or advocate of SAS, and actually recommend using other SAS alternatives, but I am somewhat addicted to the SAS Proc Freq procedure and its output tables. Its a nice way to not only visualize the data but also to get some useful summary statistics. I have been using the R table command for a while and in most cases combined with margin.table or prop.table it suffices to summarize the data. Recently, I have been in need of summary statistics for the tables as well. This can be accomplished easy enough using the R chisq.test or fisher.test commands, but still doesn't quite provide the fluid integration of data visualization and summary statistics that the SAS Proc Freq output provides. Today I came across the R package CrossTable. This procedure, part of the gmodels library, provides formatted output very similar to that of Proc Freq. So much so, it even uses the same ascii characters to delineate cell boundaries. There is a bit of playing around with options and such to get the exact statistics and percentages and such you would like, but overall a very nice (a not to mention free) alternative to SAS's Proc Freq output. Below is an example table I created.
Wednesday, January 15, 2014
Statistical Package Alternatives to SAS
Lets face it, SAS (aka Statistical Analysis Software) is an archaic program that is difficult to learn, cumbersome to code, and slow to implement calculations. While graphics are improving, graphs are still hard to customize and lag far behind those of other programs. In addition, yearly licensing fees were more than enough to scare me away, especially since there are a lot of open source statistical programing packages that are just as good, if not better than SAS.
So what are these alternatives to SAS? Here is my attempt to make a list of valid alternatives to SAS. Some may be more powerful or better tailored to specific niches than others, but all are capable of carrying out basic statistical tests. The list is alphabetical with major SAS contenders highlighted in bold.
Epi Info - simple CDC tool for clinicians
Excel - basic, but there are some useful plugins
gretl - open source with econometrics focus
KXEN - seems more geared towards industry
Mathematica - used it doing physics research, seemed powerful at the time, but a long time ago
MATLAB - again, maybe more for engineers and such, but has statistical functionality
Minitab - quite accessible to those with little computer knowledge
Octav - open source, similar to MATLAB
OpenEpi - online, JAVA based statistical applets
Python - more of a programming language, but has statistical packages you can load
R - open source, thousands of libraries and active community of users
S-Plus - similar to R, S based dialect, could not find a link to this
Sage- unified interface of open source packages
SPSS - point and click, with some scripting options, crashes a lot
Stata - command line or point and click, powerful but not bloated
STATISTICA - markets themselves as a user friendly SAS alternative
That's about as exhaustive of a list as I can come up with. If I missed something important please comment and let me know about it. Hopefully I have been able to convince you there are plenty of excellent alternative statistical programming packages to SAS that are worth your time looking into. In my opinion, R and Stata are the two clear front runners, particularly R since it is free and open source. Happy hunting for a SAS replacement!
So what are these alternatives to SAS? Here is my attempt to make a list of valid alternatives to SAS. Some may be more powerful or better tailored to specific niches than others, but all are capable of carrying out basic statistical tests. The list is alphabetical with major SAS contenders highlighted in bold.
Epi Info - simple CDC tool for clinicians
Excel - basic, but there are some useful plugins
gretl - open source with econometrics focus
KXEN - seems more geared towards industry
Mathematica - used it doing physics research, seemed powerful at the time, but a long time ago
MATLAB - again, maybe more for engineers and such, but has statistical functionality
Minitab - quite accessible to those with little computer knowledge
Octav - open source, similar to MATLAB
OpenEpi - online, JAVA based statistical applets
Python - more of a programming language, but has statistical packages you can load
R - open source, thousands of libraries and active community of users
S-Plus - similar to R, S based dialect, could not find a link to this
Sage- unified interface of open source packages
SPSS - point and click, with some scripting options, crashes a lot
Stata - command line or point and click, powerful but not bloated
STATISTICA - markets themselves as a user friendly SAS alternative
That's about as exhaustive of a list as I can come up with. If I missed something important please comment and let me know about it. Hopefully I have been able to convince you there are plenty of excellent alternative statistical programming packages to SAS that are worth your time looking into. In my opinion, R and Stata are the two clear front runners, particularly R since it is free and open source. Happy hunting for a SAS replacement!
Friday, November 15, 2013
How to Convert Number Values that Include Commas From Character to Numeric in R
Sometimes when importing data into R, especially from Excel spreadsheets, there are comma separators between every three digits to more clearly delineate the size of the number. While this is convenient visually, when importing such numbers into R it can be a bit of a headache trying to convert these numbers from character format into an analysis friendly numeric format. Here is a quick one liner of code to convert such an imported variable from character to numeric:
Essentially, this code first removes all commas by replacing them with nothing, then converts the numbers from character format to numeric format, and finally replaces the original variable with the new one.
Essentially, this code first removes all commas by replacing them with nothing, then converts the numbers from character format to numeric format, and finally replaces the original variable with the new one.
Tuesday, November 12, 2013
Relationship between Odds and Probability
It's a simple mathematical relationship, but sometimes I forget.
Odds=p/(1-p)=proportion of success/proportion of failure
p=O/(1+O)=proportion of successes
If there is a probability p of something happening, the the odds (O) is, on average, the number of successes you expect per failure. High odds correspond to high probabilities and low odds correspond to low probabilities. As the probability approaches zero, the odds is approximately equal to p. Probabilities are bound to [0,1], while odds are bound to [0,∞).
Odds=p/(1-p)=proportion of success/proportion of failure
p=O/(1+O)=proportion of successes
If there is a probability p of something happening, the the odds (O) is, on average, the number of successes you expect per failure. High odds correspond to high probabilities and low odds correspond to low probabilities. As the probability approaches zero, the odds is approximately equal to p. Probabilities are bound to [0,1], while odds are bound to [0,∞).
Friday, November 8, 2013
How to Estimate a P-value from a Confidence Interval
Confidence intervals (CIs) are useful statistical calculations to help get a level of certainty around an estimated effect size. Whenever possible, I advocate to include a CI when reporting an estimated effect size. Sometimes, however, it is of interest to back calculate a p-value from a confidence interval if the p-value is not reported in the manuscript. To do so, we need to remember the basic equations for the confidence interval and the calculation of a p-value. Assuming we are dealing with a 95% CI, we would take the effect size and subtract/add 1.96 times the standard error of the effect size to get our lower and upper bounds of the confidence interval. For the p-value, we just take the effect estimate and divide it by the standard error of the effect estimate to get a z score from which we can calculate the p-value. Therefore, if we are given an effect size and confidence interval all we need to do is back calculate the standard error and combine that with the effect size to get the z score used to calculate the p-value. Below are two examples to illustrate how to do this.
Suppose we have an estimate of a risk difference and a respective 95 percent confidence interval of 3.60 (0.70, 6.50). Here are the steps to follow:
(1) Subtract the lower limit from the upper limit to get the difference and divide by 2: (6.50-0.70)/2=2.9
(2) Divide the difference by 1.96 (for a 95% CI) to get the standard error estimate: 2.9/1.96=1.48
(3) Divide the risk difference estimate by the standard error estimate to get a z score: 3.60/1.48=2.43
(4) Look up the z score using Python, R (ex: 2*pnorm(-abs(z))), Excel (ex: 2*1-normsdist(z score)), or an online calculator to get the p-value. Usually the two-sided p-value is reported: p=0.015 (two-sided)
For an odds ratio, things are a bit trickier because we need to first take the natural log of the estimate and 95% confidence interval before we can carry out the back calculation of the standard error for calculating the p-value. Suppose we have an odds ratio and 95 percent confidence interval of 1.28 (1.05, 1.57). Here are the steps to follow:
(1) Take the natural log (ln) of each value in the 95% CI: 0.25 (0.05, 0.45)
(2) Subtract the lower limit from the upper limit and divide by 2: (0.45-0.05)/2=0.2
(3) Divide the difference by 1.96 (for a 95% CI) to get the standard error estimate: 0.2/1.96=0.10
(4) Divide the log odds ratio by the standard error estimate to get a z score: 0.25/0.10=2.50
(5) Look up the z score using Python, R (ex: 2*pnorm(-abs(z))), Excel (ex: 2*1-normsdist(z score)), or an online calculator to get the p-value. Usually the two-sided p-value is reported: p=0.012 (two-sided)
Hopefully these are good examples to get you started. As you can imagine you can also go from a p-value to a 95% confidence interval by extending these methods in the opposite direction, but in practice it is somewhat unlikely an author would report an effect size and p-value while leaving out the 95% confidence interval.
Suppose we have an estimate of a risk difference and a respective 95 percent confidence interval of 3.60 (0.70, 6.50). Here are the steps to follow:
(1) Subtract the lower limit from the upper limit to get the difference and divide by 2: (6.50-0.70)/2=2.9
(2) Divide the difference by 1.96 (for a 95% CI) to get the standard error estimate: 2.9/1.96=1.48
(3) Divide the risk difference estimate by the standard error estimate to get a z score: 3.60/1.48=2.43
(4) Look up the z score using Python, R (ex: 2*pnorm(-abs(z))), Excel (ex: 2*1-normsdist(z score)), or an online calculator to get the p-value. Usually the two-sided p-value is reported: p=0.015 (two-sided)
For an odds ratio, things are a bit trickier because we need to first take the natural log of the estimate and 95% confidence interval before we can carry out the back calculation of the standard error for calculating the p-value. Suppose we have an odds ratio and 95 percent confidence interval of 1.28 (1.05, 1.57). Here are the steps to follow:
(1) Take the natural log (ln) of each value in the 95% CI: 0.25 (0.05, 0.45)
(2) Subtract the lower limit from the upper limit and divide by 2: (0.45-0.05)/2=0.2
(3) Divide the difference by 1.96 (for a 95% CI) to get the standard error estimate: 0.2/1.96=0.10
(4) Divide the log odds ratio by the standard error estimate to get a z score: 0.25/0.10=2.50
(5) Look up the z score using Python, R (ex: 2*pnorm(-abs(z))), Excel (ex: 2*1-normsdist(z score)), or an online calculator to get the p-value. Usually the two-sided p-value is reported: p=0.012 (two-sided)
Hopefully these are good examples to get you started. As you can imagine you can also go from a p-value to a 95% confidence interval by extending these methods in the opposite direction, but in practice it is somewhat unlikely an author would report an effect size and p-value while leaving out the 95% confidence interval.
Friday, May 24, 2013
Worldwide Cancer Statistics
When drafting manuscripts and preparing presentations it is often nice to display relevant cancer statistics to give the audience a perspective of the scope of the disease. GLOBOCAN is an excellent tool that provides a variety of worldwide cancer statistics. Estimated 2008 cancer incidence, mortality, prevalence, and disability-adjusted life years (DALYs) are available for 184 countries and 27 cancer types. Although the figures are far from polished, they do provide just about any cancer statistic I could think of. Highlights include interactive maps, sex stratified analyses, and age-adjusted rates.
Subscribe to:
Posts (Atom)
