I am trying to produce a GLM using glmulti, though when I produce z values for the model, it says that they are characters rather than numerical. This also makes the p value calculation incorrect. The code for producing the importance, z values and p values is as follows:
It is not clear to me what you are trying to do:
did you already create a glmulti model with results in res1 and are you now deriving z-values for a next step? In that case also show how you created the model.
If you use one of the standard datasets of R (e.g. iris) you don't have to show you own dataset (that could be confidential).
X10m is not a dataset that I could google on the internet.
Can you provide a small subset so that we can redo your analysis?
See the link in my previous answer for methods to do that.
Hello @tomjohnson10 ,
I think the problem was that in your names(mmi1) <- .... statement you forget to name the variable/intercept term. Your calculations look alright.
library(glmulti)
#> Warning: package 'glmulti' was built under R version 4.1.1
#> Loading required package: rJava
#> Loading required package: leaps
res1<-glmulti(Sepal.Length~Sepal.Width+Petal.Length+Petal.Width, data = iris,
crit = "aicc", confsetsize = 100, fitfunction = "glm", level = 1)
#> Initialization...
#> TASK: Exhaustive screening of candidate set.
#> Fitting...
#> Completed.
# statements not relevant for this question (??) omitted
mmi1<-as.data.frame(coef(res1))
mmi1<-data.frame(Estimate=mmi1$Est, SE=sqrt(mmi1$Uncond), Importance=mmi1$Importance,row.names(mmi1))
mmi1$z<-mmi1$Estimate/mmi1$SE
mmi1$p<-2*pnorm(abs(mmi1$z),lower.tail = FALSE)
sapply(mmi1,class) # inserted HO
#> Estimate SE Importance row.names.mmi1. z
#> "numeric" "numeric" "numeric" "character" "numeric"
#> p
#> "numeric"
names(mmi1)<-c("Estimate", "Std. Error", "Importance", "variable"," z value", "Pr(>|z|)") # changed HO
mmi1$ci.lb<-mmi1[[1]]-qnorm(.975)*mmi1[[2]]
mmi1$ci.ub<-mmi1[[1]]+qnorm(.975)*mmi1[[2]]
mmi1<-mmi1[order(mmi1$Importance, decreasing = TRUE), c(1,2,4:8,3)] #changed HO
mmi1
#> Estimate Std. Error variable z value Pr(>|z|) ci.lb
#> 3 1.8561143 0.25084071 (Intercept) 7.399574 1.366224e-13 1.3644756
#> 4 0.7090615 0.05677313 Petal.Length 12.489386 8.530993e-36 0.5977882
#> 2 0.6508207 0.06665394 Sepal.Width 9.764174 1.604132e-22 0.5201814
#> 1 -0.5563173 0.12767546 Petal.Width -4.357277 1.316908e-05 -0.8065566
#> ci.ub Importance
#> 3 2.3477531 1.0000000
#> 4 0.8203348 1.0000000
#> 2 0.7814601 1.0000000
#> 1 -0.3060780 0.9997029
summary(mmi1)
#> Estimate Std. Error variable z value
#> Min. :-0.5563 Min. :0.05677 Length:4 Min. :-4.357
#> 1st Qu.: 0.3490 1st Qu.:0.06418 Class :character 1st Qu.: 4.460
#> Median : 0.6799 Median :0.09716 Mode :character Median : 8.582
#> Mean : 0.6649 Mean :0.12549 Mean : 6.324
#> 3rd Qu.: 0.9958 3rd Qu.:0.15847 3rd Qu.:10.445
#> Max. : 1.8561 Max. :0.25084 Max. :12.489
#> Pr(>|z|) ci.lb ci.ub Importance
#> Min. :0.000e+00 Min. :-0.8066 Min. :-0.3061 Min. :0.9997
#> 1st Qu.:0.000e+00 1st Qu.: 0.1885 1st Qu.: 0.5096 1st Qu.:0.9999
#> Median :0.000e+00 Median : 0.5590 Median : 0.8009 Median :1.0000
#> Mean :3.292e-06 Mean : 0.4190 Mean : 0.9109 Mean :0.9999
#> 3rd Qu.:3.292e-06 3rd Qu.: 0.7895 3rd Qu.: 1.2022 3rd Qu.:1.0000
#> Max. :1.317e-05 Max. : 1.3645 Max. : 2.3478 Max. :1.0000
Created on 2021-08-28 by the reprex package (v2.0.0)