R – Statistics

September 15, 2014

d linear regression data set

September 12, 2014

examples2

How to Run Anova Test and Tukey’s honest significant difference test (instead of Fisher’s) using R Stat

> x <- read.table(“h:\\rdata\\c.txt”,sep=” “,header=T)

Note: The “h:\\…” is the location of your file on your computer.  For Windows computers, locate your file and right click on it, select Properties and you will find the location information.  For each backslash use two backslashes.

On a Mac computer, locate your file and press apple key – i to get the location.  For macs it will be something like /users/user/c.txt.  Therefore for the location use // for the forward slash like this “//users//user//c.txt”.
> x
MethodA MethodB MethodC
1    32.2    35.0    34.5
2    37.4    31.2    38.9
3    35.9    29.3    32.5
4    28.1    28.4    33.3
5    41.0    34.1    45.8
6    44.5    38.1    48.9
7    35.6    32.6    41.1
8    31.2    31.5    37.6
9    34.8    27.7    45.7

> Material = c(x[[1]])
> Material
[1] 32.2 37.4 35.9 28.1 41.0 44.5 35.6 31.2 34.8
> Material = c(x[[1]],x[[2]],x[[3]])
> Material
[1] 32.2 37.4 35.9 28.1 41.0 44.5 35.6 31.2 34.8 35.0 31.2 29.3 28.4 34.1 38.1
[16] 32.6 31.5 27.7 34.5 38.9 32.5 33.3 45.8 48.9 41.1 37.6 45.7
> Method = c(rep(“MethodA”,9),rep(“MethodB”,9),rep(“MethodC”,9))
> mdata = data.frame(Method,Material)
> mdata
Method Material
1  MethodA     32.2
2  MethodA     37.4
3  MethodA     35.9
4  MethodA     28.1
5  MethodA     41.0
6  MethodA     44.5
7  MethodA     35.6
8  MethodA     31.2
9  MethodA     34.8
10 MethodB     35.0
11 MethodB     31.2
12 MethodB     29.3
13 MethodB     28.4
14 MethodB     34.1
15 MethodB     38.1
16 MethodB     32.6
17 MethodB     31.5
18 MethodB     27.7
19 MethodC     34.5
20 MethodC     38.9
21 MethodC     32.5
22 MethodC     33.3
23 MethodC     45.8
24 MethodC     48.9
25 MethodC     41.1
26 MethodC     37.6
27 MethodC     45.7

This rearranges the data set so you should have 2 columns and 27 rows of data as seen. Each row is assigned a Method.  For now we will call the data “Material” and this is the independent variable.  The dependent variable is Method.
> anovareport = aov(Material~Method,data=mdata)

Please note!  The ~ between Materal and Method is the tilda character!
> summary(anovareport)
This will print out the results from the Anova test.

> TukeyHSD(aov(lm(Material~Method),data=mdata),conf.level=0.95)

Please note!  The ~ between Materal and Method is the tilda character!

This will print out the results from Tukey.  This will show the different in means between the Methods, the 95% confidence interval and the P probability the mean difference is within the confidence interval.
> summary(x)

A summary of the x table.
September 11, 2014

examples

a data set

c data set

 

Leave a Reply

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