I am new to r and I am a function written to perform Cochran's Q test for homogeneity. I am trying to find the p value but the function returns a std. error instead of a p value as you can see below. I fear I may have written the code incorrectly. Please help if you can.
dput(g1):
c(Estimate = 0.89502349171762, `Std. Error` = 0.198551047700126,
`z value` = 4.50777521491291, `Pr(>|z|)` = 6.55109263453831e-06
dput(g2):
c(Estimate = 0.798619626770536, `Std. Error` = 0.0963490218317536,
`z value` = 8.28881924888765, `Pr(>|z|)` = 1.14378204173144e-16
dput(g3):
c(Estimate = 0.493965082375263, `Std. Error` = 0.27251885149614,
`z value` = 1.81259050397201, `Pr(>|z|)` = 0.0698950035163995
Qtest <- function(g1,g2,g3){
w1 <- 1/(g1["Std. Error"])^2
w2 <- 1/(g2["Std. Error"])^2
w3 <- 1/(g3["Std. Error"])^2
avg <- (w1*g1["Estimate"] + w2*g2["Estimate"]+ w3*g3["Estimate"])/(w1+w2+w3)
test <- w1*(g1["Estimate"]-avg)^2 + w2*(g2["Estimate"] - avg)^2+ w3*(g3["Estimate"] - avg)^2
pval <- 1-pchisq(test, df=1)
return(pval)
}
Qtest(g1,g2,g3)
# Std. Error
# 0.225857