# One Sample Analysis in R

#### Hypothesis:

One sample analysis in R-In statistics, we can define the corresponding null hypothesis  (H0) as follow:

1.      H0:m=μ,

2.      H0:m≤μ

3.      H0:m≥μ

The corresponding alternative hypotheses (Ha)  as follow:

1.      Ha:m≠μ (different)

2.      Ha:m>μ (greater)

3.      Ha:m<μ (less)

#### Outlier Detection:

Out.fun<-function{abs(x-mean(x,na.rm=TRUE))>3*sd(x,na.rm=TRUE)}

ddply(data,.(sample, variable),transform,outlier.team=out.fun(value))

column heading should be sample, variable, value

Check outlier detection based on above formula and remove if any

#### Shapiro-Wilk test:

1. Null hypothesis: the data are normally distributed.
2. Alternative hypothesis: the data are not normally distributed

shapiro.test(data\$weight)

From the output, the p-value is greater than the significance level 0.05 implying that the distribution of the data is not significantly different from normal distribution. In other words, we can assume the normality.

#### Parametric Method:

one-sample t-test is used to compare the mean of one sample to a known standard (or theoretical/hypothetical) mean (μ). one-sample t-test can be used only, when the data are normally distributed.

##### one-sample t-test
###### two.sided

To perform one-sample t-test, the R function t.test() can be used as follow:

t.test(x, mu = 0, alternative = “two.sided”)

###### one sided

t.test(data\$weight, mu = 2, alternative = “less”)

t.test(data\$weight, mu = 2, alternative = “greater”)

#### Non Parametric Method:

The one-sample Wilcoxon signed rank test is a non-parametric alternative to one-sample t-test when the data cannot be assumed to be normally distributed. It’s used to determine whether the median of the sample is equal to a known standard value (i.e. theoretical value).

##### one-sample Wilcoxon test
###### two.sided

To perform one-sample Wilcoxon-test, the R function wilcox.test() can be used as follow:

wilcox.test(x, mu = 0, alternative = “two.sided”)

###### one sided

wilcox.test(data\$weight, mu = 2, alternative = “less”)

wilcox.test(data\$weight, mu = 2, alternative = “greater”)

#### Interpretation

The p-value of the test which is less than the significance level alpha = 0.05. We can conclude that the mean weight is significantly different from 2g with a p-value x.

t test in R

proportion test in R

### 2 Responses

1. Explain something says:

Good job

2. Jai Shree Radhe 🙏🙏 says:

Nice post 