当前位置:网站首页>Analysis of variance
Analysis of variance
2022-06-28 20:15:00 【Burger jingle】
4.4 variance analysis
4.4.1 One way ANOVA and python Realization
* One way ANOVA : Consider only one factor in an experiment A The change of
example 4.22 use 4 Technology A1, A2, A3,A4 produce lamps , Several bulbs made by various processes were taken out to measure their service life , Results such as table 4.10 Shown , Try to infer whether there is a significant difference in the service life of bulbs made by these processes .

See you for the explanation P151——P155
import numpy as np
import statsmodels.api as sm
y=np.array([1620, 1670, 1700, 1750, 1800, 1580, 1600, 1640, 1720,
1460, 1540, 1620, 1680, 1500, 1550, 1610])
x=np.hstack([np.ones(5), np.full(4,2), np.full(4,3), np.full(3,4)])// Modify this row when adding data , This row is to build the table
d= {'x':x,'y':y} # Construct a dictionary
model = sm.formula.ols("y~C(x)",d).fit() # Build the model
anovat = sm.stats.anova_lm(model) # One way ANOVA
print(anovat) 
PR=0.042004<0.05, Therefore, there is a significant difference in the service life of bulbs made by these processes

example 4.23( Balanced data ) To investigate 5 Whether the labor productivity of workers is the same , Recorded each person 4 Days of production , Determine whether there is a significant difference in their productivity .

import numpy as np
import pandas as pd
import statsmodels.api as sm
df = pd.read_excel("Pdata4_23.xlsx", header=None)
a=df.values.T.flatten()
print(a)
b=np.arange(1,6)// Modify this line directly
x=np.tile(b,(4,1)).T.flatten()
print(x)
d={'x':x,'y':a} # Construct the dictionary needed for solving
model = sm.formula.ols("y~C(x)",d).fit() # Build the model
anovat = sm.stats.anova_lm(model) # One way ANOVA
print(anovat) 
PR=0.110913>0.05, So there is no significant difference
4.4.2 Two factor analysis of variance and python Realization
1. mathematical model
It is divided into : Two factor ANOVA with interaction effect and two factor ANOVA without interaction effect
( Combined with the F Test method )
2. Realization

# Program files Pex4_24.py
import numpy as np
import statsmodels.api as sm
y=np.array([[11, 11, 13, 10], [10, 11, 9, 12],
[9, 10, 7, 6], [7, 8, 11, 10],
[5, 13, 12, 14], [11, 14, 13, 10]]).flatten()
A=np.tile(np.arange(1,5),(6,1)).flatten()# Temperature minute 4 Group
B=np.tile(np.arange(1,4).reshape(3,1),(1,8)).flatten()# Concentration points 3 Group
# Be careful , When modifying data A,B All have to be revised. , Such as
#y=np.array([[11, 11, 13, 10,1], [10, 11, 9, 12,1],
# [9, 10, 7, 6,1], [7, 8, 11, 10,1],
# [5, 13, 12, 14,1], [11, 14, 13, 10,1]]).flatten()
#A=np.tile(np.arange(1,6),(6,1)).flatten()# Temperature minute 4 Group
#B=np.tile(np.arange(1,4).reshape(3,1),(1,10)).flatten()# Concentration points 3 Group
d={'x1':A,'x2':B,'y':y}
model = sm.formula.ols("y~C(x1)+C(x2)+C(x1):C(x2)",d).fit() # Notice how the interaction formula is written
anovat = sm.stats.anova_lm(model) # Two way ANOVA was performed
print(anovat)边栏推荐
猜你喜欢

数论 --- 欧拉函数、筛法求欧拉函数、欧拉定理、费马小定理详细证明

2022 t elevator repair test question bank simulation test platform operation

Number theory -- detailed proof of Euler function, sieve method for Euler function, Euler theorem and Fermat theorem

计网 | 一文解析TCP协议所有知识点

还在付费下论文吗?快来跟我一起白piao知网

2022茶艺师(中级)考试模拟100题及模拟考试

Are you still paying for your thesis? Come and join me

Jenkins pipeline's handling of job parameters

On the first anniversary of the data security law, which four major changes are coming?

5g NR MBS architecture introduction
随机推荐
类加载机制与对象的创建
2022年P气瓶充装考试练习题及在线模拟考试
蓝桥杯 历届试题 蚂蚁感冒
Huawei cloud onemeeting tells you that the whole scene meeting is held like this!
【毕业季·进击的技术er】努力只能及格,拼命才能优秀!
[algorithm] I brushed two big factory interview questions and learned array again with tears in my eyes“
C # application interface development foundation - form control
2022焊工(初级)特种作业证考试题库及答案
TcWind 模式設定
UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation
严重性 代码 说明 项目 文件 行 禁止显示状态 错误 C1047 对象或库文件“.lib”是使用与其他对象(如“x64\Release\main.obj”)不同的
新形势下的SaaS销售升级|ToB大师课
Fix the simulator that cannot be selected by flutter once
5g NR MBS architecture introduction
1. 整合 Servlet
[go language questions] go from 0 to entry 5: comprehensive review of map, conditional sentences and circular sentences
wc命令的使用
A few lines of code can realize complex excel import and export. This tool class is really powerful!
The severity code indicates that the project file line prohibits the display of status errors. C1047 object or library file ".Lib" is different from other objects (such as "x64\release\main.obj")
计网 | 一文解析TCP协议所有知识点