Friday, 14 December 2018

One-way analysis of means

> x = c(5, 5, 5, 13, 7, 11, 11, 9, 8, 9)
> y = c(11, 8, 4, 5, 9, 5, 10, 5, 4, 10)
>
> boxplot(x,y)

> boxplot(x,y)
> y=rnorm(1000)
> f=factor(rep(1:10,100))
> boxplot(y ~ f,main="Boxplot of normal random data with model notation")

> x = rnorm(100)
> y = factor(rep(1:10,10))
> stripchart(x ~ y)
> par(mfrow=c(1,3))
> data(InsectSprays)
> boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
> plot(x,y)



> x = 1:10
> y = sample(1:100,10)
> z = x+y
> lm(z ~ x+y)

Call:
lm(formula = z ~ x + y)

Coefficients:
(Intercept)            x            y 
  2.472e-14    1.000e+00    1.000e+00 

> z = x+y + rnorm(10,0,10)
> lm(z ~ x+y)

Call:
lm(formula = z ~ x + y)

Coefficients:
(Intercept)            x            y 
     -5.888        0.484        1.180 

> lm(z ~ x+y -1)

Call:
lm(formula = z ~ x + y - 1)

Coefficients:
       x         y 
-0.05044   1.13803 

> summary(lm(z ~ x+y ))

Call:
lm(formula = z ~ x + y)

Residuals:
    Min      1Q  Median      3Q     Max
-12.993  -6.778   0.519   6.582  13.599

Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept)  -5.8883     9.1775  -0.642    0.542   
x             0.4840     1.1287   0.429    0.681   
y             1.1803     0.1011  11.675 7.64e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 10.19 on 7 degrees of freedom
Multiple R-squared:  0.9514, Adjusted R-squared:  0.9375
F-statistic: 68.49 on 2 and 7 DF,  p-value: 2.534e-05

> x = c(4,3,4,5,2,3,4,5)
> y = c(4,4,5,5,4,5,4,4)
> z = c(3,4,2,4,5,5,4,4)
> scores = data.frame(x,y,z)
> boxplot(scores)
> scores = stack(scores)
> names(scores)
[1] "values" "ind" 
> oneway.test(values ~ ind, data=scores, var.equal=T)

One-way analysis of means

data:  values and ind
F = 1.1308, num df = 2, denom df = 21, p-value = 0.3417

> df = stack(data.frame(x,y,z))
> oneway.test(values ~ ind, data=df,var.equal=T)

One-way analysis of means

data:  values and ind
F = 1.1308, num df = 2, denom df = 21, p-value = 0.3417

> anova(lm(values ~ ind, data=df))
Analysis of Variance Table

Response: values
          Df Sum Sq Mean Sq F value Pr(>F)
ind        2   1.75 0.87500  1.1308 0.3417
Residuals 21  16.25 0.77381             
>
> kruskal.test(values ~ ind, data=df)

Kruskal-Wallis rank sum test

data:  values by ind
Kruskal-Wallis chi-squared = 1.9387, df = 2, p-value = 0.3793

No comments:

Post a comment

Intersection of subring

How to prove the intersection of two subrings is a subring? Let S1 and S2  be two subrings of a ring R. Then S1∩S2 is not empty since ...