问题描述
我不是统计学家,我需要在python中转换一些SAS功能。我需要一个公式或python代码,可以提供此语句创建的变异系数(C.V。):
proc mixed covtest CL;
by loc;
class line rep;
model &var=line ;
random rep;
estimate 'testmean' intercept 1;
lsmean line/diff=all;
ods output diffs=db30;
ods output lsmeans;
ods listing exclude all;
我目前正在使用此python代码,但CV已关闭。数据集仅是3列-品种的Entrycode,Rep列,Plot列和yield列:
#Calculate the mean and CV
mean = round(new_data['YLD'].mean(),1)
x = new_data[['ENTRYCODE','REP']]
cv = gs.calccv(new_data,x,''YLD ~ C(ENTRYCODE) + C(REP)','YLD',mean)
def calccv(dataset,formula,var,varmean):
#########################################
# Purpose: #
# Calculate the Coefficient of Variance #
# Inputs: #
# dataSet - test dataset #
# X = factors for the X axis #
# formula - statistical model used #
# var - variable to be checked #
#########################################
model = ols(formula,data=dataset).fit()
y_predict = model.predict(x)
rsme_calc = rmse(dataset[var],y_predict)
cv = round(100 * (rsme_calc / varmean),1)
std = dataset[var].std()
cv = round(100 * (std/varmean))
return cv
任何帮助将不胜感激。
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)