Posts

Showing posts from June, 2015

Calculating P-values in R

Notes below are documented for future reference should I ever need to use them again someday. A pharmaceutical company is interested in testing a potential blood pressure lowering medication. Their first examination considers only subjects that received the medication at baseline then two weeks later. The data are as follows (SBP in mmHg) SubjectBaselineWeek 211401322138135315015141481465135130Consider testing the hypothesis that there was a mean reduction in blood pressure? Give the P-value for the associated two sided T test. (Hint, consider that the observations are paired). Solution: baseline<- span=""> c(140,138,150,148,135)week2<-c(132,135,151,146,130)round(t.test(baseline,week2, paired=TRUE)$p.value,3)## [1] 0.087Researchers conducted a blind taste test of Coke versus Pepsi. Each of four people was asked which of two blinded drinks given in random order that they preferred. The data was such that 3 of the 4 people chose Coke. Assu

Hypothesis testing and confidence interval in R

As usual, the notes below are documented for future reference should I ever need to use them again someday. Also to note, most of the exercises this time around requires that you’d be able to generate a random data set in a precise manner - else you wouldn’t get the same answer as what was provided in the exercises. You’d think that R already has a function on that but sadly no. Due to the small sample sizes in most of the questions, rnorm wouldn’t usually give you an accurate result. It’d instead give you something like this: a<- rnorm(10, 5, 1)mean(a)## [1] 5.081355sd(a)## [1] 0.7624848 Lucky for me, I was able to find this nice function right here Stack Overflow rnorm2<- function(n,mean,sd){mean+sd*scale(rnorm(n))} It’s very similar to rnorm - only more precise and behaves exactly as you’d expect a random number generator to behave. Let’s take it for a test run. b<- rnorm2(10,5,1)mean(b)## [1] 5sd(b

Comparing Exponential Distribution With Central Limit Theorem

Image
Some notes based on my statistical studies. A good reference on how do simulations in R to prove and gain better grasp in understanding the Central Limit Theorem (CLT), and how CLT can even be used when your original data is not a normal distribution.
Or maybe perhaps you just prefer the video - Understanding Central Limit Theorem - with Bunnies and Dragons
Overview
In this report we will investigate the exponential distribution in R and compare it with the Central Limit Theorem.
Simulations
The exponential distribution will be simulated in R using rexp(n,lambda) where lambda is the rate parameter. The mean of exponential distribution is 1/lambda and the standard deviation is also 1/lambda. We will use lambda = 0.2 for all of the simulations. We will illustrate via simulation and associated explanatory text the properties of the distribution of the mean of 40 exponentials. Among our findings would be: The sample mean and it’s comparison to the theoretical mean of the distribution.The …