You are on page 1of 22

R version 3.4.

2 (2017-09-28) -- "Short Summer"

Copyright (C) 2017 The R Foundation for Statistical Computing

Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under certain conditions.

Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.

Type 'contributors()' for more information and

'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or

'help.start()' for an HTML browser interface to help.

Type 'q()' to quit R.

> tyre.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\tyre.csv")

> attach(tyre.dat)

> View(tyre.dat)

> setwd("C:\\Users\\Abhishek\\Desktop\R")

Error: '\R' is an unrecognized escape in character string starting ""C:\\Users\\Abhishek\\Desktop\R"

> setwd("C:\\Users\\Abhishek\\Desktop\\R")

> getwd()

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

> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---

Error in contrib.url(repos, type) :

trying to use CRAN without setting a mirror

> install.packages("reshape2")

Warning in install.packages("reshape2") :

'lib = "C:/Program Files/R/R-3.4.2/library"' is not writable

--- Please select a CRAN mirror for use in this session ---

also installing the dependencies stringi, magrittr, plyr, stringr, Rcpp

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/stringi_1.1.6.zip'

Content type 'application/zip' length 14295451 bytes (13.6 MB)

downloaded 10.8 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/magrittr_1.5.zip'

Content type 'application/zip' length 155661 bytes (152 KB)

downloaded 152 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/plyr_1.8.4.zip'

Content type 'application/zip' length 1218698 bytes (1.2 MB)

downloaded 1.2 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/stringr_1.2.0.zip'

Content type 'application/zip' length 149122 bytes (145 KB)

downloaded 145 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/Rcpp_0.12.14.zip'

Content type 'application/zip' length 4358749 bytes (4.2 MB)


downloaded 4.2 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/reshape2_1.4.2.zip'

Content type 'application/zip' length 609603 bytes (595 KB)

downloaded 595 KB

Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :

cannot open the connection

In addition: Warning messages:

1: In download.file(url, destfile, method, mode = "wb", ...) :

downloaded length 11350016 != reported length 14295451

2: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file

3: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :

cannot open compressed file 'stringi/DESCRIPTION', probable reason 'No such file or directory'

> data=read.csv("C:\User\\Abhishek\\Desktop\\R\\Q1.csv")

> data=read.csv("C:\\User\\Abhishek\\Desktop\\R\\Q1.csv")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") :

cannot open file 'C:\User\Abhishek\Desktop\R\Q1.csv': No such file or directory

> brands

Error: object 'brands' not found

> Brands

[1] Apollo Apollo Apollo Apollo Apollo Apollo

[7] Apollo Apollo Apollo Apollo Apollo Apollo

[13] Apollo Apollo Apollo Bridgestone Bridgestone Bridgestone


[19] Bridgestone Bridgestone Bridgestone Bridgestone Bridgestone Bridgestone

[25] Bridgestone Bridgestone Bridgestone Bridgestone Bridgestone Bridgestone

[31] CEAT CEAT CEAT CEAT CEAT CEAT

[37] CEAT CEAT CEAT CEAT CEAT CEAT

[43] CEAT CEAT CEAT Falken Falken Falken

[49] Falken Falken Falken Falken Falken Falken

[55] Falken Falken Falken Falken Falken Falken

Levels: Apollo Bridgestone CEAT Falken

> is.factor(Brands)

[1] TRUE

> Brands=as.factor(Brands)

> tyre.aov=aov(Mileage~Brands)

> summary(tyre.aov)

Df Sum Sq Mean Sq F value Pr(>F)

Brands 3 256.3 85.43 17.94 2.78e-08 ***

Residuals 56 266.6 4.76

---

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

> TukeyHSD(tyre.aov, conf.level = 0.99)

Tukey multiple comparisons of means

99% family-wise confidence level

Fit: aov(formula = Mileage ~ Brands)

$Brands

diff lwr upr p adj

Bridgestone-Apollo -3.01900000 -5.6155816 -0.4224184 0.0020527


CEAT-Apollo -0.03792661 -2.6345082 2.5586550 0.9999608

Falken-Apollo 2.82553333 0.2289517 5.4221149 0.0043198

CEAT-Bridgestone 2.98107339 0.3844918 5.5776550 0.0023806

Falken-Bridgestone 5.84453333 3.2479517 8.4411149 0.0000000

Falken-CEAT 2.86345994 0.2668783 5.4600415 0.0037424

> pairwise.t.test(Mileage, Brands,p.adjust.method = "bonferroni")

Pairwise comparisons using t tests with pooled SD

data: Mileage and Brands

Apollo Bridgestone CEAT

Bridgestone 0.0022 - -

CEAT 1.0000 0.0026 -

Falken 0.0048 5.8e-09 0.0041

P value adjustment method: bonferroni

> shapiro.test(Mileage[1:15])

Shapiro-Wilk normality test

data: Mileage[1:15]

W = 0.95353, p-value = 0.5817

> shapiro.test(Mileage[16:30])
Shapiro-Wilk normality test

data: Mileage[16:30]

W = 0.95509, p-value = 0.6078

> shapiro.test(Mileage[31:45])

Shapiro-Wilk normality test

data: Mileage[31:45]

W = 0.95228, p-value = 0.561

> shapiro.test(Mileage[46:60])

Shapiro-Wilk normality test

data: Mileage[46:60]

W = 0.9692, p-value = 0.846

> bartlett.test(Mileage~Brands)

Bartlett test of homogeneity of variances

data: Mileage by Brands

Bartlett's K-squared = 2.1496, df = 3, p-value = 0.5419

> Revenue.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Revenue.csv")
> attach(Revenue.dat)

> View(Revenue.dat)

> str(Revenue.dat)

'data.frame': 5 obs. of 13 variables:

$ YEAR: int 2012 2013 2014 2015 2016

$ JAN : int 15 18 22 23 24

$ FEB : int 22 25 15 15 14

$ MAR : int 18 22 15 19 21

$ APR : int 23 15 14 17 18

$ MAY : int 23 15 26 18 14

$ JUN : int 12 15 11 10 8

$ JUL : int 26 12 23 15 18

$ AUG : int 19 17 15 20 10

$ SEPT: int 15 14 18 19 20

$ OCT : int 14 18 10 12 23

$ NOV : int 14 22 19 17 11

$ DEC : int 21 23 11 18 14

> library(reshape2)

Error in library(reshape2) : there is no package called reshape2

> mrevenue.dat<- melt(revenue.dat, id.var="YEAR")

Error in melt(revenue.dat, id.var = "YEAR") :

could not find function "melt"

> install.packages("reshape2")

Installing package into C:/Users/Abhishek/Documents/R/win-library/3.4

(as lib is unspecified)

also installing the dependencies stringi, magrittr, plyr, stringr, Rcpp


trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/stringi_1.1.6.zip'

Content type 'application/zip' length 14295451 bytes (13.6 MB)

downloaded 13.6 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/magrittr_1.5.zip'

Content type 'application/zip' length 155661 bytes (152 KB)

downloaded 152 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/plyr_1.8.4.zip'

Content type 'application/zip' length 1218698 bytes (1.2 MB)

downloaded 1.2 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/stringr_1.2.0.zip'

Content type 'application/zip' length 149122 bytes (145 KB)

downloaded 145 KB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/Rcpp_0.12.14.zip'

Content type 'application/zip' length 4358749 bytes (4.2 MB)

downloaded 4.2 MB

trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/reshape2_1.4.2.zip'

Content type 'application/zip' length 609603 bytes (595 KB)

downloaded 595 KB

package stringi successfully unpacked and MD5 sums checked

package magrittr successfully unpacked and MD5 sums checked

package plyr successfully unpacked and MD5 sums checked


package stringr successfully unpacked and MD5 sums checked

package Rcpp successfully unpacked and MD5 sums checked

package reshape2 successfully unpacked and MD5 sums checked

The downloaded binary packages are in

C:\Users\Abhishek\AppData\Local\Temp\Rtmp88jhqb\downloaded_packages

> library(reshape2)

> mrevenue.dat<- melt(revenue.dat, id.var="YEAR")

Error in melt(revenue.dat, id.var = "YEAR") :

object 'revenue.dat' not found

> View(Revenue.dat)

> mrevenue.dat<- melt(revenue.dat, id.var="YEAR")

Error in melt(revenue.dat, id.var = "YEAR") :

object 'revenue.dat' not found

> mrevenue.dat<- melt(Revenue.dat, id.var="YEAR")

> View(mrevenue.dat)

> attach(mrevenue.dat)

The following object is masked from Revenue.dat:

YEAR

> fit=aov(revenue~month + year)

Error in eval(predvars, data, env) : object 'revenue' not found

> fit=aov(Revenue~ month + years)

Error in eval(predvars, data, env) : object 'Revenue' not found

> Rev.aov=aov(value~YEAR + variable)

> summary(Rev.aov)
Df Sum Sq Mean Sq F value Pr(>F)

YEAR 1 37.4 37.41 2.120 0.152

variable 11 308.4 28.04 1.589 0.133

Residuals 47 829.4 17.65

> Dirt.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Dirt.csv")

> attach(Dirt.dat)

> View(Dirt.dat)

> summary(aov.deter)

Error in summary(aov.deter) : object 'aov.deter' not found

> Sales1.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Sales1.csv")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") :

cannot open file 'C:\Users\Abhishek\Desktop\QT2-Exam\Sales1.csv': No such file or directory

> Sales1.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Sales1.csv")

> attach(tyre.dat)

The following object is masked _by_ .GlobalEnv:

Brands

The following objects are masked from tyre.dat (pos = 7):

Brands, Mileage

> attach(Sales1.dat)

> View(Sales1.dat)

> shapiro.test(Groups[1:4])
Error in stopifnot(is.numeric(x)) : object 'Groups' not found

> shapiro.test(Group[1:15])

Error: is.numeric(x) is not TRUE

> shapiro.test(Group[1:4])

Error: is.numeric(x) is not TRUE

> shapiro.test(Sales[1:4])

Shapiro-Wilk normality test

data: Sales[1:4]

W = 0.99994, p-value = 0.9999

> shapiro.test(Mileage[16:30])

Shapiro-Wilk normality test

data: Mileage[16:30]

W = 0.95509, p-value = 0.6078

> shapiro.test(Mileage[31:45])

Shapiro-Wilk normality test

data: Mileage[31:45]

W = 0.95228, p-value = 0.561

> shapiro.test(Sales[5:8])
Shapiro-Wilk normality test

data: Sales[5:8]

W = 0.94466, p-value = 0.683

> shapiro.test(Sales[9:12])

Shapiro-Wilk normality test

data: Sales[9:12]

W = 0.94971, p-value = 0.7143

> bartlett.test(Sales~Group)

Error in bartlett.test.default(c(16L, 18L, 21L, 13L, 19L, 20L, 21L, 20L, :

there must be at least 2 observations in each group

> bartlett.test(Sales~Group)

Error in bartlett.test.default(c(16L, 18L, 21L, 13L, 19L, 20L, 21L, 20L, :

there must be at least 2 observations in each group

> bartlett.test(Sales~Group)

Error in bartlett.test.default(c(16L, 18L, 21L, 13L, 19L, 20L, 21L, 20L, :

there must be at least 2 observations in each group

> Sales1.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Sales1.csv")

> attach(Sales1.dat)

The following objects are masked from Sales1.dat (pos = 3):

Group, Sales
> View(Sales1.dat)

> bartlett.test(Sales~Group

Error: unexpected end of input

> bartlett.test(Sales~Group)

Error in bartlett.test.default(c(16L, 18L, 21L, 13L, 19L, 20L, 21L, 20L, :

there must be at least 2 observations in each group

> bartlett.test(Sales~Group)

Error in bartlett.test.default(c(16L, 18L, 21L, 13L, 19L, 20L, 21L, 20L, :

there must be at least 2 observations in each group

> Sales1.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Sales1.csv")

> attach(Sales1.dat)

The following objects are masked from Sales1.dat (pos = 3):

Group, Sales

The following objects are masked from Sales1.dat (pos = 4):

Group, Sales

> View(Sales1.dat)

> bartlett.test(Sales~Group)

Bartlett test of homogeneity of variances

data: Sales by Group


Bartlett's K-squared = 4.3583, df = 2, p-value = 0.1131

> Sales1.aov=aov(Sales~Group,Sales1.dat)

> summary(Sales1.aov)

Df Sum Sq Mean Sq F value Pr(>F)

Group 2 72 36.00 7.043 0.0144 *

Residuals 9 46 5.11

---

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

> TukeyHSD(Sales1.aov, conf.level = 0.99)

Tukey multiple comparisons of means

99% family-wise confidence level

Fit: aov(formula = Sales ~ Group, data = Sales1.dat)

$Group

diff lwr upr p adj

G2-G1 3 -3.1357962 9.135796 0.2007063

G3-G1 6 -0.1357962 12.135796 0.0113595

G3-G2 3 -3.1357962 9.135796 0.2007063

> Pressure2.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Pressure2.csv")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") :

cannot open file 'C:\Users\Abhishek\Desktop\QT2-Exam\Pressure2.csv': No such file or directory

> Pressure2.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Pressure2.csv")
> attach(Pressure2.dat)

> View(Pressure2.dat)

>

> View(Pressure2.dat)

> Pressure2.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Pressure2.csv")

> attach(Pressure2.dat)

The following objects are masked from Pressure2.dat (pos = 3):

CarType, Pressure

> View(Pressure2.dat)

> Pressure3.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Pressure3.csv")

> attach(Pressure2.dat)

The following objects are masked from Pressure2.dat (pos = 3):

CarType, Pressure

The following objects are masked from Pressure2.dat (pos = 4):

CarType, Pressure

> View(Pressure2.dat)

> attach(Pressure3.dat)

The following objects are masked from Pressure2.dat (pos = 3):

CarType, Pressure
The following objects are masked from Pressure2.dat (pos = 4):

CarType, Pressure

The following objects are masked from Pressure2.dat (pos = 5):

CarType, Pressure

> View(Pressure3.dat)

> bartlett.test(Pressure~CarType')

Error: unexpected end of input

> bartlett.test(Pressure~CarType)

Bartlett test of homogeneity of variances

data: Pressure by CarType

Bartlett's K-squared = 0.93979, df = 2, p-value = 0.6251

> Pressure3.aov=aov(CarType~Pressure,Pressure2.dat)

Warning messages:

1: In model.response(mf, "numeric") :

using type = "numeric" with a factor response will be ignored

2: In Ops.factor(y, z$residuals) : - not meaningful for factors

> summary(Pressure3.aov)

Error in levels(x)[x] : only 0's may be mixed with negative subscripts


> Pressure3.aov=aov(Pressure~CarType,Pressure3.dat)

> summary(Pressure3.aov)

Df Sum Sq Mean Sq F value Pr(>F)

CarType 2 71894 35947 27.46 0.000955 ***

Residuals 6 7854 1309

---

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

> TukeyHSD(Pressure3.aov, conf.level = 0.99)

Tukey multiple comparisons of means

99% family-wise confidence level

Fit: aov(formula = Pressure ~ CarType, data = Pressure3.dat)

$CarType

diff lwr upr p adj

Full-Size-Compact -186 -318.2354 -53.7646 0.0018163

MidSized-Compact -193 -325.2354 -60.7646 0.0014942

MidSized-Full-Size -7 -139.2354 125.2354 0.9696757

> Ass3.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Ass3.csv")

> attach(Ass3.dat)

> View(Ass3.dat)

> Ass3.aov=aov(Score~Brand + Taster,Ass3.dat)

> summary(Ass3.aov)

Df Sum Sq Mean Sq F value Pr(>F)

Brand 2 141.91 70.96 19.21 5.6e-06 ***

Taster 14 32.58 2.33 0.63 0.818


Residuals 28 103.42 3.69

---

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

> summary(Ass3.aov)

> cor.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Adv_Sales_cor.csv")

> attach(cor.dat)

The following object is masked from Sales1.dat (pos = 8):

Sales

The following object is masked from Sales1.dat (pos = 9):

Sales

The following object is masked from Sales1.dat (pos = 10):

Sales

> view(cor.dat)

Error in view(cor.dat) : could not find function "view"

> adv.dat=read.csv("C:\\Users\\Abhishek\\Desktop\\QT2-Exam\\Adv_Sales_cor.csv")

> attach(adv.dat)

The following objects are masked from cor.dat:

Advertising, Sales
The following object is masked from Sales1.dat (pos = 9):

Sales

The following object is masked from Sales1.dat (pos = 10):

Sales

The following object is masked from Sales1.dat (pos = 11):

Sales

> View(adv.dat)

> cor(Advertising,Sales)

[1] 0.6314276

> cor(Advertising,Sales)^2

[1] 0.3987008

> cor.test(Advertising,Sales)

Pearson's product-moment correlation

data: Advertising and Sales

t = 4.7481, df = 34, p-value = 3.635e-05

alternative hypothesis: true correlation is not equal to 0

95 percent confidence interval:

0.3821722 0.7950359

sample estimates:
cor

0.6314276

> cor.test(Advertising,Sales,method="Spearman")

Error in match.arg(method) :

'arg' should be one of pearson, kendall, spearman

> cor.test(Advertising,Sales,method="spearman")

Spearman's rank correlation rho

data: Advertising and Sales

S = 2844.1, p-value = 3.308e-05

alternative hypothesis: true rho is not equal to 0

sample estimates:

rho

0.6339626

Warning message:

In cor.test.default(Advertising, Sales, method = "spearman") :

Cannot compute exact p-value with ties

> cor.test(Advertising,Sales,method="kemdall")

Error in match.arg(method) :

'arg' should be one of pearson, kendall, spearman

> cor.test(Advertising,Sales,method="kendall")

Kendall's rank correlation tau


data: Advertising and Sales

z = 3.9834, p-value = 6.793e-05

alternative hypothesis: true tau is not equal to 0

sample estimates:

tau

0.4694631

Warning message:

In cor.test.default(Advertising, Sales, method = "kendall") :

Cannot compute exact p-value with ties

> Model1=lm(Sales~Advertising)

> lm=(formula=Sales~Advertising)

> abline(Model1)

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :

plot.new has not been called yet

> Model1=lm(Sales~Advertising)

> lm=(formula=Sales~Advertising)

> plot(Sales~Advertising)

> abline(Model1)

> summary(Model1)

Call:

lm(formula = Sales ~ Advertising)

Residuals:

Min 1Q Median 3Q Max

-31.593 -8.186 -0.783 9.727 32.039


Coefficients:

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

(Intercept) -17.992 10.102 -1.781 0.0839 .

Advertising 1.918 0.404 4.748 3.64e-05 ***

---

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

Residual standard error: 14.77 on 34 degrees of freedom

Multiple R-squared: 0.3987, Adjusted R-squared: 0.381

F-statistic: 22.54 on 1 and 34 DF, p-value: 3.635e-05

> lm=(formula=(Sales^2)~Advertising)

> plot(Sales~Advertising)

> lm2=(formula=(Sales^2)~Advertising)

> Model3=lm(I(Sales^2)~Advertising)

> Model1=lm(Sales~Advertising)

You might also like