我需要一个Python初学者的帮助。我改编了一个来自R的程序,它对用户在Q and df
字段中输入的两个变量(Q,df)进行一些计算。在
我的问题是:如何让程序在适当的字段(I2, 95%LL, 95%UL)
中显示I2, I2_LL and I2_UL
结果?在
我的原始代码,在没有图形界面的情况下非常完美:
import math
from scipy.stats import norm
while True:
while True:
try:
Q = float(input("Introduceti valoarea Q: "))
except ValueError:
print("Introdu un numar!")
continue
if Q < 0:
print("Q trebuie sa aiba o valoare pozitiva")
continue
else:
break
while True:
try:
df = float(input("Introduceti valoarea df: "))
except ValueError:
print("Introdu un numar!")
continue
if df < 2:
print("df trebuie sa aiba o valoare mai mare sau egala cu 2")
continue
else:
break
K = df + 1
level = 95
levelci = level * 0.005 + 0.50
clevelci = 1 - levelci
if Q >= K:
SElnH = 0.5 * ((math.log(Q) - math.log(df)) / (math.sqrt(2 * Q) - math.sqrt(2 * K - 3)))
else:
SElnH = math.sqrt((1 / (2 * (K - 2)) * (1 - 1 / (3 * (K - 2) ** 2))))
H = math.sqrt(Q / df)
H2 = (Q / df)
H_LL = math.exp(math.log(math.sqrt(H2)) - norm.ppf(levelci) * SElnH)
H_UL = math.exp(math.log(math.sqrt(H2)) + norm.ppf(levelci) * SElnH)
I2 = (100 * (Q - df)) / Q
I22 = (H2 - 1) / H2
varI2 = 4 * SElnH ** 2 / math.exp(4 * math.log(math.sqrt(H2)))
I2_LL = (I22 - norm.ppf(levelci) * math.sqrt(varI2)) * 100
I2_UL = (I22 + norm.ppf(levelci) * math.sqrt(varI2)) * 100
print("--------------------------------------------------------------------------")
print("Statistic" + " " + " |" + "Estimate" + " " + " [95% Confidence Interval]")
print("--------------------------------------------------------------------------")
print(" H" + " ------->" + "|" + str(H) + " [" + str(H_LL) + " to " + str(H_UL) + "]")
print("I^2" + " ------->" + "|" + str(I2) + " [" + str(I2_LL) + " to " + str(I2_UL) + "]")
print("--------------------------------------------------------------------------")
while True:
answer = str(input("Introduceti alte valori? (da/nu): "))
if answer in ("da, nu"):
break
print("Raspuns invalid.")
if answer == "da":
continue
else:
print("Bye bye")
break
我正在努力解决的问题是:
^{2}$感谢您对初学者的耐心:-)
这应该能让你。。。在
而不是
试试看这:在
^{pr2}$我认为问题在于,您试图在填充条目之前获取条目的值。我建议你在你的按钮上连接一个函数来执行计算。结果是这样的:
相关问题 更多 >
编程相关推荐