For Better Performance Please Use Chrome or Firefox Web Browser

Computational Statistics (98-99)

تمرین امتیازی: تابعی بنویسید که بتواند جدول آنالیز واریانس را در مدل رگرسیون خطی چندگانه گزارش دهد.

 

پاسخ از آقای آرش آقایی

f=function(x,y,z,alpha){
  Y=x[,y]
  a=as.matrix(x[,z])
  mymodel=lm(Y~a)
  M=anova(mymodel)
  SSE=round(M["Residual","Sum Sq"],digits=3)
  n=length(Y)
  SSY=round(var(Y)*(n-1),digits=3)
  SSR=SSY-SSE
  F_value=round((SSR/length(z))/(SSE/(n-length(z)-1)),digits=3)
  Critic=round(qf(1-alpha,length(z),n-length(z)-1),digits=3)
  if(F_value>Critic){
    i="Model is significant"
  }
  else{
    i="Model is not significant"
  }
  t=matrix(c(SSR,SSE,SSY,length(z),n-length(z)-1,n-1,round(SSR/length(z),digits=3),round(SSE/(n-length(z)-1),digits=3),"_",F_value,"_","_",Critic,"_","_",i,"_","_"),ncol=6)
  colnames(t)=c(" SS "," DF ","MS "," Statistics "," Critical "," Result ")
  rownames(t)=c("Regression ","Residual ","Total ")
  tab=as.table(t)
  tab
}

#############################################################################
highway=read.table("C:\\.............................\\highway1.txt",header=TRUE)
f(highway,2,c(10,7,3,8),0.05)
f(highway,"rate",c("acpt","slim","len","shld"),0.05)

 

 

 

Prerequisites: 

-

Grading Policy: 

-

Time: 

-

تحت نظارت وف ایرانی