Salta ai contenuti. | Salta alla navigazione

Strumenti personali

Lab 8_MLRM intro

Plain Text icon Lab 8_MLRM-intro.txt — Plain Text, 1 kB (1440 bytes)

Contenuto del file

##### UNIFE SEB lab - 1.03.2019 -  MINI
### MLRM
### research question: do advertising and price affect the total sales of pie?

getwd()

torta<-read.csv2("torta.csv")

# analyze the database
View(torta)
str(torta)
head(torta)

#describe the variables

attach(torta)
torta=torta[,-1]# we deleted week from our in-use database because we are not interest
# we rename our variables of interest: 
x1=Price
x2=Advertising
y=Pie.sales

#1. graphical analysis

plot(x1,y)
plot(x2,y)
pairs(x=torta,panel=panel.smooth)

#2.identify the coefficients of our model

#we may use two methods: glm () or lm() [let's start with lm]

reg=lm(y~x1+x2)

reg

#to identify the coefficients and the method used


summary(reg)

#please, try to explain all the part composing our output


####  OUR MODEL: y= 306.53-24.98*Price+74.13*Advertising

#3. graphical representation (you should have the 3D software)
library(scatterplot3d) # let's check the availability of the 3D
 
sc=scatterplot3d(y,x1,x2)


#4. Let's make a prediction

#ex. price=5$, advertise=410 $ ( -> the value is 4.1)

b0=306.53
b1=-24.93
b2=74.13
pred=b0+b1*5+b2*4.1
pred  #485.813


#5.the goodness of fit of our model

#5A= RQ from the output
#5B= from the ANOVA

#let's go head with the exercises 5a and 5b and compare the obtained values

summary(reg)

anova(reg) #(11100+1836)/(11100+18360+27033)