大学僧,在学R语言,要考试了,代码还没搞明白,,,求大神帮忙,应该是最基础的了
library (ElemStatLearn)
data(prostate)
data1=prostate[,-10]
myff=function(i,data1){
getz=function(n,k){
z=rep(0,k)
tn=n
for(j in 2:k){
tn=(tn-z[j-1]/2
if(tn==0) break
z[j]=tn%%2}
as.logical(z)}
mylm=function(j,fam,data1){
kk=dim(data1)[2]
lm1=lm(fam,data1[j,])
predict(lm1,data1[j,]-data1[j,kk])^2}
dma=names(data1)
k=dim(data1)[2]-1
n=dim(data1)[1]
tm1=paste(dma[k+1],"~",sep="")
z=getz(i,k)
tm2=paste((dma[1:k])[z],collapse="+")
fam=formula(paste(tm1,tm2,sep=""))
lm1=lm(fam,data1)
c(mean(apply(matrix(1:n,n),1,mylm,fam,data1)),extractAIC(lm1)[2])
}
re2=apply(matrix(1:225,225),1,myff,data1)
希望大神能告诉我每句话是什么意思,为啥这么写,每个参数又是什么,括号里面一堆逗号那种
手机一点点打的不容易,谢谢啦! |