Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Class 7

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

> getwd()

[1] "C:/Users/user/Documents"

> setwd(C:/Users/user/Desktop/R)

Error: unexpected '/' in "setwd(C:/"

> setwd("C:/Users/user/Desktop/R")

> getwd()

[1] "C:/Users/user/Desktop/R"

> bdt = read.csv("BschoolData.csv", header=TRUE)

> bdt

Student Salary.000

1 1 750

2 2 600

3 3 600

4 4 650

5 5 700

6 6 780

7 7 860

8 8 810

9 9 780

10 10 670

11 11 690

12 12 550

13 13 610

14 14 715

15 15 755

16 16 770

17 17 680

18 18 670

19 19 740
20 20 760

21 21 775

22 22 845

23 23 870

24 24 640

25 25 690

26 26 715

27 27 630

28 28 685

29 29 780

30 30 635

> head(bdt)

Student Salary.000

1 1 750

2 2 600

3 3 600

4 4 650

5 5 700

6 6 780

> plot (bdt, col ="orange", type ="h", lwd = 3, main = "package for 30 students")

Warning messages:

1: graphical parameter "type" is obsolete

2: graphical parameter "type" is obsolete

> abline ( h = mean (sa), lty = 4, col= "green")

> abline ( h = t5avgsal , lty = 4, col= "blue")

> abline ( h = median(sa) , lty = 4, col= "blue")

> abline ( h = median(sa) , lty = 4, col= "red")


> require ("psych")

Loading required package: psych

> summary (sa)

Min. 1st Qu. Median Mean 3rd Qu. Max.

550.0 655.0 707.5 713.5 773.8 870.0

> describe (sa)

vars n mean sd median trimmed mad min max range skew

X1 1 30 713.5 81.26 707.5 711.67 96.37 550 870 320 0.08

kurtosis se

X1 -0.83 14.84

ONE SAMPLE T-TEST

> t.test (sa, mu = 750)

One Sample t-test

data: sa

t = -2.4601, df = 29, p-value = 0.02009

alternative hypothesis: true mean is not equal to 750

95 percent confidence interval:

683.1558 743.8442

sample estimates:

mean of x

713.5

> t.test (sa, mu = 100)

One Sample t-test


data: sa

t = 41.351, df = 29, p-value < 2.2e-16

alternative hypothesis: true mean is not equal to 100

95 percent confidence interval:

683.1558 743.8442

sample estimates:

mean of x

713.5

> t.test (sa, mu = 500)

One Sample t-test

data: sa

t = 14.39, df = 29, p-value = 9.751e-15

alternative hypothesis: true mean is not equal to 500

95 percent confidence interval:

683.1558 743.8442

sample estimates:

mean of x

713.5

> t.test (sa, mu = 713.5)

One Sample t-test

data: sa

t = 0, df = 29, p-value = 1

alternative hypothesis: true mean is not equal to 713.5


95 percent confidence interval:

683.1558 743.8442

sample estimates:

mean of x

713.5

> t.test (sa, mu = 750, conf.level = 0.99)

One Sample t-test

data: sa

t = -2.4601, df = 29, p-value = 0.02009

alternative hypothesis: true mean is not equal to 750

99 percent confidence interval:

672.6047 754.3953

sample estimates:

mean of x

713.5

> mdt = read.csv("MinersData.csv",header = TRUE)

> mdt

Worker Mine Output

1 1 1 48

2 2 1 45

3 3 1 33

4 4 1 39

5 5 1 34

6 6 1 49

7 7 1 33
8 8 1 45

9 9 1 48

10 10 1 44

11 11 1 45

12 12 1 45

13 13 1 36

14 14 1 48

15 15 1 41

16 16 1 47

17 17 1 39

18 18 1 49

19 19 1 38

20 20 1 45

21 21 2 42

22 22 2 44

23 23 2 41

24 24 2 39

25 25 2 35

26 26 2 34

27 27 2 33

28 28 2 36

29 29 2 37

30 30 2 37

31 31 2 41

32 32 2 42

33 33 2 39

34 34 2 38

35 35 2 38

36 36 2 39
37 37 2 41

38 38 2 40

39 39 2 41

40 40 2 40

41 41 2 38

42 42 2 41

43 43 2 43

44 44 2 40

> head (mdt)

Worker Mine Output

1 1 1 48

2 2 1 45

3 3 1 33

4 4 1 39

5 5 1 34

6 6 1 49

> tail (mdt)

Worker Mine Output

39 39 2 41

40 40 2 40

41 41 2 38

42 42 2 41

43 43 2 43

44 44 2 40

> attach (mdt)

> attributes (mdt)

$names

[1] "Worker" "Mine" "Output"


$class

[1] "data.frame"

$row.names

[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

[22] 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

[43] 43 44

> subset (Mine)

Error in subset.default(Mine) :

argument "subset" is missing, with no default

> mdt1 = subset (mdt, Mine==1)

> mdt2 = subset (mdt, Mine==2)

> mdt1

Worker Mine Output

1 1 1 48

2 2 1 45

3 3 1 33

4 4 1 39

5 5 1 34

6 6 1 49

7 7 1 33

8 8 1 45

9 9 1 48

10 10 1 44

11 11 1 45

12 12 1 45

13 13 1 36

14 14 1 48
15 15 1 41

16 16 1 47

17 17 1 39

18 18 1 49

19 19 1 38

20 20 1 45

> mdt2

Worker Mine Output

21 21 2 42

22 22 2 44

23 23 2 41

24 24 2 39

25 25 2 35

26 26 2 34

27 27 2 33

28 28 2 36

29 29 2 37

30 30 2 37

31 31 2 41

32 32 2 42

33 33 2 39

34 34 2 38

35 35 2 38

36 36 2 39

37 37 2 41

38 38 2 40

39 39 2 41

40 40 2 40

41 41 2 38
42 42 2 41

43 43 2 43

44 44 2 40

> plot (Output, col = "red", type = "l")

> attach (mdt1)

The following objects are masked from mdt:

Mine, Output, Worker

> attach (mdt2)

The following objects are masked from mdt1:

Mine, Output, Worker

The following objects are masked from mdt:

Mine, Output, Worker

> points (Output, col = "red", type = "l")

> dev.off()

null device

> attach (mdt1)

The following objects are masked from mdt2:

Mine, Output, Worker

The following objects are masked from mdt1 (pos = 4):


Mine, Output, Worker

The following objects are masked from mdt:

Mine, Output, Worker

> par (mfrow = c(1,2))

> attach (mdt1)

The following objects are masked from mdt1 (pos = 3):

Mine, Output, Worker

The following objects are masked from mdt2:

Mine, Output, Worker

The following objects are masked from mdt1 (pos = 5):

Mine, Output, Worker

The following objects are masked from mdt:

Mine, Output, Worker

> plot (Output, col = "red",type = "h", lwd = 3)

> attach (mdt2)

The following objects are masked from mdt1 (pos = 3):

Mine, Output, Worker


The following objects are masked from mdt1 (pos = 4):

Mine, Output, Worker

The following objects are masked from mdt2 (pos = 5):

Mine, Output, Worker

The following objects are masked from mdt1 (pos = 6):

Mine, Output, Worker

The following objects are masked from mdt:

Mine, Output, Worker

> plot (Output, col = "blue",type = "h", lwd = 3)

> attach (mdt)

> describeBy (mdt, Mine)

Descriptive statistics by group

group: 1

vars n mean sd median trimmed mad min max range skew

Worker 1 20 10.50 5.92 10.5 10.50 7.41 1 20 19 0.0

Mine 2 20 1.00 0.00 1.0 1.00 0.00 1 1 0 NaN

Output 3 20 42.55 5.48 45.0 42.94 5.19 33 49 16 -0.5


kurtosis se

Worker -1.38 1.32

Mine NaN 0.00

Output -1.27 1.23

--------------------------------------------------

group: 2

vars n mean sd median trimmed mad min max range skew

Worker 1 24 32.50 7.07 32.5 32.50 8.90 21 44 23 0.00

Mine 2 24 2.00 0.00 2.0 2.00 0.00 2 2 0 NaN

Output 3 24 39.12 2.79 39.5 39.25 2.22 33 44 11 -0.45

kurtosis se

Worker -1.35 1.44

Mine NaN 0.00

Output -0.57 0.57

Two Sample t-test


t.test (Output~Mine)

Welch Two Sample t-test

data: Output by Mine

t = 2.5345, df = 27.03, p-value = 0.01736

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

95 percent confidence interval:

0.65244 6.19756

sample estimates:

mean in group 1 mean in group 2

42.550 39.125
PAIRED SAMPLE TEST

> data = read.csv ("BT_AT_Data.csv", header = TRUE)

> data

Employee Ef.Bt Ef.At

1 1 41 44

2 2 35 36

3 3 40 48

4 4 50 47

5 5 39 40

6 6 45 52

7 7 35 35

8 8 36 51

9 9 44 46

10 10 40 55

11 11 46 39

12 12 42 40

13 13 37 36

14 14 34 39

15 15 38 50

16 16 42 46

17 17 46 49

18 18 39 42

19 19 40 51

20 20 45 37

> attach (data)

> t.test (Ef.Bt, Ef.At, paired = TRUE)

Paired t-test
data: Ef.Bt and Ef.At

t = -2.3913, df = 19, p-value = 0.02729

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

95 percent confidence interval:

-6.4696523 -0.4303477

sample estimates:

mean of the differences

-3.45
> data = read.csv ("BT_AT_Data.csv", header = TRUE)

> data

Employee Ef.Bt Ef.At Difference

1 1 41 44 -3

2 2 35 36 -1

3 3 40 48 -8

4 4 50 47 3

5 5 39 40 -1

6 6 45 52 -7

7 7 35 35 0

8 8 36 51 -15

9 9 44 46 -2

10 10 40 55 -15

11 11 46 39 7

12 12 42 40 2

13 13 37 36 1

14 14 34 39 -5

15 15 38 50 -12

16 16 42 46 -4

17 17 46 49 -3

18 18 39 42 -3

19 19 40 51 -11

20 20 45 37 8

> attach (data)

The following objects are masked from data (pos = 3):

Difference, Ef.At, Ef.Bt, Employee


The following objects are masked from data (pos = 4):

Ef.At, Ef.Bt, Employee

> barplot (Difference, col ="orange")

> barplot (Difference, col ="orange", xlab = "Employee", ylab = "Difference between before and after")

> barplot (Difference, col ="orange", xlab = "Employee", ylab = "Difference between before and after",
main = "Effectiveness of training")

> t.test (Difference)

One Sample t-test

data: Difference

t = -2.3913, df = 19, p-value = 0.02729

alternative hypothesis: true mean is not equal to 0

95 percent confidence interval:

-6.4696523 -0.4303477

sample estimates:

mean of x

-3.45

>

You might also like