# How to calculate standardized regression coefficients with beta.glm function in r having weights in my model?

At the moment I am running logistic regressions on individual data with weights. Here is my model:

model <- glm(Dummy_WBT_17~ hinc2 + tmp_b4p_bildung_quote + benefits_7 + benefits_10 + Dummy_PartyID + gender + age_rec + region_rec + urban, weights = weight, data=new3, family=binomial)


In a next step I wanted to calculate standardized regression coefficients with beta glm from 'reghelper' package . But I receive the following error:

beta(model)
Error in eval(extras, data, env) : object 'weight' not found


There is no error if I exclude the weights from my model. So I think the error is due to using weights in my model. Do you have any idea how to calculate standardized regression coefficients inculding the weights?

Thank you!

• do you have an object or variable in your workspace called 'weight'? The error appears to be that r is unable to find an object with that exact name. Have you checked capitalisation and plural/singular is consistent? – ReneBt May 29 '18 at 8:45
• I checked everything. Capitalisation and plural/singular is consistent. The variable in my data 'new3' is called 'weight'. So I wonder why R claims that there is no object 'weight'. Maybe it's a more general problem, such that you can't calculate standardized coefficients if you weight your data... – Lars Bischoff May 29 '18 at 9:42

## 1 Answer

Well the problem seems to be a little bit strange. We tried the following:

test=model$model names(test) [1] "Dummy_WBT_17" [2] "hinc2" [3] "tmp_b4p_bildung_quote" [4] "benefits_7" [5] "benefits_10" [6] "Dummy_PartyID" [7] "gender" [8] "age_rec" [9] "region_rec" [10] "urban" [11] "(weights)"  It seems like the glm function renamed automatically the variable weight into "(weights)". That explains why beta function claims: "object 'weight' not found". Since it wasn't possible to rename "(weight)" into weights, we created a new variable which is simply a copy of "(weight)" and renamed it. model$model[,12] = model$model[,11] names(model$model)[12]="weight"


And now the beta function works.

beta(model)