R语言 python aovova 方差分析,运行结果正确,能帮忙核对下么

R语言 python aovova 方差分析,运行结果正确,能帮忙核对下么

R语言转成python. 求助

R 语言如下

for(i in 1:nz){

y<- StableM[StableM$Parameter==paste(z[i,1]),c("filename","Group","Value")]

if( (nrow(y)>=5) && (length(unique(y$Group))>1))

{z[i,2]<- summary(aov(as.numeric(y$Value) ~ y$Group, data=y )) [[1]] [[1,"Pr(>F)"]]}

}

Python 写成了下面的样子,运行应该是正确的没有问题吧

 y<- StableM[StableM$Parameter==paste(z[i,1]),c("filename","Group","Value")]

{z[i,2]<- summary(aov(as.numeric(y$Value) ~ y$Group, data=y )) [[1]] [[1,"Pr(>F)"]]}

from statsmodels.formula.api import ols

from statsmodels.stats.anova import anova_lm

z = StableM['Par'].drop_duplicates()### extract abnormal

par_list = z.tolist()

z = pd.DataFrame(z)

z.loc[:,'pValue'] = 1 #df_one = pd.DataFrame(np.ones((z.size,1),dtype = np.int), columns=['pValue'])

nz =z.shape[0]

#p_value= pd.DataFrame({'pValue':[]})

for i in range(0,nz): #print(i) -> 0,1

y = StableM[StableM['Par'] == par_list[i]] # paste(..., sep = " ", collapse = NULL)

if (y.shape[0] >=5) & (len(y['Group'].unique()) > 1):

model = ols('Value ~ C(Group)',y).fit()

anovat = anova_lm(model)

aov_table = anova_lm(model, typ=2)

z.loc[z['Par'] == par_list[i],'pValue'] = aov_table['PR(>F)'].iloc[0] # UpperHeat OutPut pvalue = 1.9472e-05

print(anovat) #PR(>F) p-value

以上是 R语言 python aovova 方差分析,运行结果正确,能帮忙核对下么 的全部内容, 来源链接: utcz.com/p/938166.html

回到顶部