0% found this document useful (0 votes)
30 views3 pages

R Code

The document describes several statistical tests used to analyze sample data, including t-tests, Mann-Whitney U tests, simple linear regression, and multiple linear regression. A t-test shows a significant difference between mean weights of men and women in a sample. Simple linear regression of variables x and y yields a model that explains 90.9% of the variation in the data. Multiple linear regression of variable c on a and b produces a model that is not a significant fit to the data.

Uploaded by

Moidin Afsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

R Code

The document describes several statistical tests used to analyze sample data, including t-tests, Mann-Whitney U tests, simple linear regression, and multiple linear regression. A t-test shows a significant difference between mean weights of men and women in a sample. Simple linear regression of variables x and y yields a model that explains 90.9% of the variation in the data. Multiple linear regression of variable c on a and b produces a model that is not a significant fit to the data.

Uploaded by

Moidin Afsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

******* Hypothesis testing*******

Example Data with 2 variables:

women_weight <- c(38.9, 61.2, 73.3, 21.8, 63.4, 64.6, 48.4, 48.8, 48.5)

men_weight <- c(67.8, 60, 63.4, 76, 89.4, 73.3, 67.3, 61.3, 62.4)

****Parametric test: T test*******

t.test(women_weight, men_weight, var.equal=TRUE)

*****Output******

Two Sample t-test

data: women_weight and men_weight

t = -2.7842, df = 16, p-value = 0.01327

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

-29.748019 -4.029759

sample estimates:

mean of x mean of y

52.10000 68.98889

****Non-parametric test: Mann-Whitney U test*****

wilcox.test(women_weight, men_weight)

Wilcoxon rank sum test with continuity correction

data: women_weight and men_weight

W = 15, p-value = 0.02712

alternative hypothesis: true location shift is not equal to 0

*******Simple Regression********

x = c(18,23,25,35,65,54,34,56,72,19,23,42,18,39,37)

y = c(202,186,187,180,156,169,174,172,153,199,193,174,198,183,178)

simple_lm <- lm(x~y)

summary(simple_lm)

Call:

lm(formula = x ~ y)

Residuals:

Min 1Q Median 3Q Max


-10.4749 -2.7768 0.1777 3.7102 9.2459

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 242.76692 18.07239 13.43 5.34e-09 ***

y -1.13961 0.09995 -11.40 3.85e-08 ***

---

Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 5.472 on 13 degrees of freedom

Multiple R-squared: 0.9091, Adjusted R-squared: 0.9021

F-statistic: 130 on 1 and 13 DF, p-value: 3.848e-08

************Multiple Regression****************

a = c(1,2,3,4,5,6,7,8,9,10)

b= c(52, 23,12,34,23,12,45,46,23,23)

c= c(100,223,233,125,246,574,244,234,111,824)

multiple_reg<- lm(c~ a+b)

summary(multiple_reg)

Call:

lm(formula = c ~ a + b)

Residuals:

Min 1Q Median 3Q Max

-345.73 -69.91 -27.71 87.05 330.86

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 267.518 204.005 1.311 0.231

a 36.404 22.331 1.630 0.147

b -6.018 4.754 -1.266 0.246

Residual standard error: 202 on 7 degrees of freedom


Multiple R-squared: 0.3999, Adjusted R-squared: 0.2284

F-statistic: 2.332 on 2 and 7 DF, p-value: 0.1674

You might also like