One Sample Analysis in R

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

Hypothesis:

1.      H0:m=μ, 

2.      H0:m≤μ

3.      H0:m≥μ

The corresponding alternative hypotheses (Ha) are 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 the above formula and remove if any.

Log Rank Test in R-Survival Curve Comparison »

Shapiro-Wilk test:

Ho: Null hypothesis: the data are normally distributed.

H1: Alternative hypothesis: the data are not normally distributed

shapiro.test(data$weight) 

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

Parametric Method:

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

One sample analysis in R

one-sample t-test

two.sided

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

LSTM Network in R » Recurrent Neural network » finnstats

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 a 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).

How to run R code in PyCharm? » R & PyCharm »

one-sample Wilcoxon test

two.sided

To perform a 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 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.

What are the Nonparametric tests? » Why, When and Methods »

You may also like...

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × two =

Ads Blocker Image Powered by Code Help Pro

Quality articles need supporters. Will you be one?

You currently have an Ad Blocker on.

Please support FINNSTATS.COM by disabling these ads blocker.