Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 线性模型错误还是数据类型错误?_R - Fatal编程技术网

R 线性模型错误还是数据类型错误?

R 线性模型错误还是数据类型错误?,r,R,该程序生成一个带有位置和处理的矩阵。我从正态分布生成一些数据。然后尝试拟合一个基于处理和位置的预测产量的线性模型。线性模型不起作用。为什么? trts = paste(0:6) locs = paste(1:6) reps = paste(1:4) plotsize = 4 DF = expand.grid(locs, reps, trts, plotsize, stringsAsFactors = TRUE) colnames(DF) = c("Location","Replicate","T

该程序生成一个带有位置和处理的矩阵。我从正态分布生成一些数据。然后尝试拟合一个基于处理和位置的预测产量的线性模型。线性模型不起作用。为什么?

trts = paste(0:6)
locs = paste(1:6)
reps = paste(1:4)
plotsize = 4
DF = expand.grid(locs, reps, trts, plotsize, stringsAsFactors = TRUE)
colnames(DF) = c("Location","Replicate","Treatment")
vector = rnorm(1000000, mean=138.2, sd=54.89)
DF$Treatment = as.numeric(DF$Treatment)
DF$Location = as.numeric(DF$Location)
#This approach takes one set of "plotsize" values from "vector" and adds for 5 for each treatment.
DF$Yield = apply(DF, 1, function(x) (5*DF$Treatment)+mean(sample vector,plotsize)))
DF<-t(DF)
Yield<-DF$Yield
trt=as.factor(DF$Treatment)
loc=as.factor(DF$Location)
summary(fm1 <- aov(Yield ~ loc*trt))
result1<-TukeyHSD(fm1, "trtm", ordered = TRUE)
trts=粘贴(0:6)
locs=粘贴(1:6)
重复次数=粘贴(1:4)
plotsize=4
DF=展开.grid(LOC、REP、TRT、plotsize、stringsAsFactors=TRUE)
colnames(DF)=c(“位置”、“复制”、“治疗”)
向量=rnorm(1000000,平均值=138.2,标准差=54.89)
DF$Treatment=as.numeric(DF$Treatment)
DF$Location=as.numeric(DF$Location)
#这种方法从“vector”中提取一组“plotsize”值,并为每个处理添加5。
DF$收益率=应用(DF,1,函数(x)(5*DF$处理)+平均值(样本向量,绘图大小)))

d您的代码不工作,在
平均值(样本向量、绘图大小)
处中断。您打算在那里做什么?我希望它转到“向量”提取“plotsize”样本数,找到平均值,然后返回到“DF$Yield”。如果治疗=0,则仅此而已。对于治疗=1,它将在该平均值上增加5分。对于治疗=2,将在该平均值上增加10分。等等最终,有必要为每个“治疗”获得一组新的“向量”