0% found this document useful (0 votes)
4 views4 pages

ANOVA and Regression Analysis in R

Uploaded by

umaimaakif566
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)
4 views4 pages

ANOVA and Regression Analysis in R

Uploaded by

umaimaakif566
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

Assignment-4 (Using R Software)

1. One –way ANOVA in R (Weiss Example 16.3, p-722 pdf) Lecture 13 page-10

First arrange the data in an Excel file and save the file as csv (call it energy .csv), t hen in R using
these commands:
[Link]<-[Link]("[Link]", header=TRUE)
attach([Link])
[Link]=aov(consumption~Region, data=[Link])
summary([Link])

Results will be like this

(i) Perform ANOVA using the above R codes


(ii) Test the appropriate hypothesis (at 5% LOS) use both critical value and p-value
approaches.
2. Simple Regression in R
Relation between student’s population and quarterly sales of Pizza (Anderson page 687)
x<-c(2,6,8,8,12,16,20,20,22,26)
y<-c(58,105,88,118,117,137,157,169,149,202)
plot(x,y)
plot(x,y, xlab="Student Population", ylab="Sales")
lm(y~x)
summary(lm(y~x))

(i) Estimate the simple linear regression model using the above R codes.
(ii) Write down the estimated equation.
(iii) Interpret the coefficients.
(iv) Predict the quarterly sales of Pizza when student’s population is 15.
(v) Interpret R squared.
(vi) Test the appropriate hypothesis at 5% LOS (use p-value approach).
3. Multiple regression in R (Orion Car Data)
orion=[Link]([Link](), header=TRUE) # choose [Link] data
orion<-[Link]("[Link]",header=TRUE) ## alternatively used
attach(orion)
head(orion)
model.1=lm(price~age+miles, data=orion)
summary(model.1)
round((summary(model.1)$coefficients), 5) # to preset outcome with 5 decimals (avoid scientific
notation)
(i) Estimate the multiple regression model using the above R codes.
(ii) Write down the estimated equation.
(iii) Interpret all coefficients.
(iv) Predict the car price for 5-year old car with 50,000 miles driven.
(v) Interpret R squared.
(vi) Test the appropriate hypothesis at 5% L.O.S (use p-value approach).
4. Multiple Regression with One Categorical Variable.
Consider the factors such as the number of megapixels, weight (oz.), and overall score ranges
from 0 to 100 of sample of Canon and Nikon cameras used to explain prices.

Observation Brand Price_$ Megapixels Weight _oz Score Brand1


1 Canon 330 10 7 66 1
2 Canon 200 12 5 66 1
3 Canon 300 12 7 65 1
4 Canon 200 10 6 62 1
5 Canon 180 12 5 62 1
6 Canon 200 12 7 61 1
7 Canon 200 14 5 60 1
8 Canon 130 10 7 60 1
9 Canon 130 12 5 59 1
10 Canon 110 16 5 55 1
11 Canon 90 14 5 52 1
12 Canon 100 10 6 51 1
13 Canon 90 12 7 46 1
14 Nikon 270 16 5 65 0
15 Nikon 300 16 7 63 0
16 Nikon 200 14 6 61 0
17 Nikon 400 14 7 59 0
18 Nikon 120 14 5 57 0
19 Nikon 170 16 6 56 0
20 Nikon 150 12 5 56 0
21 Nikon 230 14 6 55 0
22 Nikon 180 12 6 53 0
23 Nikon 130 12 6 53 0
24 Nikon 80 12 7 52 0
25 Nikon 80 14 7 50 0
26 Nikon 100 12 4 46 0
27 Nikon 110 12 5 45 0
28 Nikon 130 14 4 42 0

(i) Estimate the regression model,


(ii) Write down the estimated equation.
(iii) Interpret the coefficients.
(iv) Predict price of Nikon camera of 14 megapixels with a weight of 6 oz and score of 55.
(v) Interpret R squared.
(vi) Test the hypothesis (at 5%) that the average price of Canon is significantly less than
Nikon.
To get the answers of above questions, Run the following R codes

camera1 = [Link]([Link]()) # File must be saved in csv (Select [Link])


attach(camera1)
head(camera1)
[Link]=lm( Price~Megapixels+Weight+Score+Brand1, data=camera1)
summary([Link])

5. Multiple Regression with More Categorical Variables (Data in file [Link])

Consider the data of sales prices of 176 houses to be explained by value of land, value of
improvement (all three variables in $1000) and the city area where the house is located.
(CHEVAL is the base area).
(i) Obtain the estimated regression using R codes.
^
Sales=−16.93+1.594 Land +1.301 Imp−82.97 DAVISISLES+10.187 HUNTERSGREE
−47.28 HYDEPARK
SE 20.33 0.091 0.0468 32.536 22.731 28.396
(ii) Interpret each coefficient.
(iii) Predict the price of a house located in Cheval that has value of land and improvement as
100 and 200 (thousands of dollars).
(iv) Test the hypothesis (at 5%) that average prices in the Hyde park area are significantly less
than Cheval area. (t 0.05, 170 df)
(v) Test the hypothesis (at 5%) that average prices in the Huntersgreen area are significantly
greater than Cheval area. (t 0.05, 170 df)

To get the answers of above questions, Run the following R codes

property = [Link]([Link]()) # File must be saved in csv (Select [Link])


attach(property)
head(property)
[Link]=lm(sales~land+imp+DAV+HUNT+HYD, data=property)
summary([Link])
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -16.93689 20.33754 -0.833 0.4061
land 1.59419 0.09116 17.489 <2e-16 ***
imp 1.30108 0.04688 27.754 <2e-16 ***
DAV -82.97736 32.53676 -2.550 0.0116 *
HUNT 10.18708 22.73161 0.448 0.6546
HYD -47.28121 28.39076 -1.665 0.0977.
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 111.3 on 170 degrees of freedom


Multiple R-squared: 0.9277, Adjusted R-squared: 0.9256
F-statistic: 436.1 on 5 and 170 DF, p-value: < 2.2e-16

You might also like