###Simple Linear Regression Model using R ###UNIFE ###Spring Semester ###Mini V. 27-02-2019 #recall the prev analysis: #we already performed our regression analysis 1-6 getwd() cake=read.csv2("cake_reg lin.csv") attach(cake) View(cake) y=sold_cakes x=unit_price reg_lin=lm(y~x) #TOPIC: the strength of the correlation between x and y within the population #we test the system of hypothesis based on the correlation coefficient RHO (?) # #H0: RHO=0 (no correlation) #H1: RHO dif. from 0 (correlazione –with given intensity) #if t-statr > v.c. --> we reject H0 --> thus, it exists a correlation –with a given intensity – within the reality between x and y #tstat.r=(r-RHO)/root.sq of ((1-r^2)/n-2)) c.v.: a/2 and d.f = n-2 dev.tot=sum((y-mean(y))^2) #total residuals SST dev.disp=sum(reg_lin$residuals^2) #residuals SSE dev.reg=dev.tot-dev.disp #regression’s residuals SSR r=sqrt(dev.reg/dev.tot) r #there is a "moderate/strong" positive correlation num=r #numerator of tstat.r den=sqrt((1-(dev.reg/dev.tot))/32) # denominator of tstat.r tstat.r=num/den tstat.r #5.208465 vc.r=qt(0.025,32) vc.r #-2.037 # (ABS VALUE!): tstat.r>C.V.r --> we reject H0 --> it exists a correlation –whit that given strenght- within the reality # significant correlation between x and y #