Everyone, im going to run logistic regression with SAFETY data. Here is my code:
library(lmtest) data <- read.csv("C:/Users/user/Desktop/SAFETY.csv",header=TRUE)(your directory) data$Type<-factor(data$Type) data$Size<-factor(data$Size) data$Region<-factor(data$Region) mylogit<- glm(Unsafe~Size+Weight+Region, data=data,family = "binomial") waldtest(mylogit,test="Chisq") then it is worked.
but if:
df <- read.csv("C:/Users/user/Desktop/SAFETY.csv",header=TRUE) df$Type<-factor(df$Type) df$Size<-factor(df$Size) df$Region<-factor(df$Region) mylogit<- glm(Unsafe~Size+Weight+Region, data=df,family = "binomial") waldtest(mylogit,test="Chisq") It shows:
Error " 'data' argument is of the wrong type"
May i know how to solve it if i insist to use name of df?? Thanks for helping.
1 Answer
I could not reproduce this issue on R 3.2.2 and lmtest 0.9.34 (see sessionInfo() output at the end).
Using this code:
library(lmtest) dfS = read.csv("Data/SAFETY.csv") logitS = glm(Unsafe ~ factor(Size) + Weight + Region, data = dfS, family = binomial()) summary(logitS) waldtest(logitS, test = "Chisq") I was able to produce:
> summary(logitS) Call: glm(formula = Unsafe ~ factor(Size) + Weight + Region, family = binomial(), data = dfS) Deviance Residuals: Min 1Q Median 3Q Max -1.7970 -0.5866 -0.3119 0.7864 2.2018 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 2.7285 1.3949 1.956 0.05046 . factor(Size)2 -2.0200 0.6246 -3.234 0.00122 ** factor(Size)3 -2.6785 0.8810 -3.040 0.00236 ** Weight -0.6678 0.4589 -1.455 0.14559 RegionN America -0.3775 0.5624 -0.671 0.50203 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 119.249 on 95 degrees of freedom Residual deviance: 84.004 on 91 degrees of freedom AIC: 94.004 Number of Fisher Scoring iterations: 5 > waldtest(logitS, test = "Chisq") Wald test Model 1: Unsafe ~ factor(Size) + Weight + Region Model 2: Unsafe ~ 1 Res.Df Df Chisq Pr(>Chisq) 1 91 2 95 -4 23.987 8.035e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 My suggestion would be for you to restart your R session and reload all required packages. Do a rm(list = ls()) if required (CAUTION: this will remove all objects from your workspace).
> sessionInfo() R version 3.2.2 (2015-08-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lmtest_0.9-34 zoo_1.7-12 tidyr_0.3.1 samplesize_0.2-2 ggplot2_1.0.1 [6] lazyeval_0.1.10 RMySQL_0.10.7 DBI_0.3.1 dplyr_0.4.3 loaded via a namespace (and not attached): [1] Rcpp_0.12.1 magrittr_1.5 MASS_7.3-43 munsell_0.4.2 colorspace_1.2-6 [6] lattice_0.20-33 R6_2.1.1 stringr_1.0.0 plyr_1.8.3 tools_3.2.2 [11] parallel_3.2.2 grid_3.2.2 gtable_0.1.2 assertthat_0.1 digest_0.6.8 [16] reshape2_1.4.1 labeling_0.3 stringi_0.5-5 scales_0.3.0 proto_0.3-10 0