easystats / modelbased

:chart_with_upwards_trend: Estimate effects, contrasts and means based on statistical models
https://easystats.github.io/modelbased/
GNU General Public License v3.0
234 stars 19 forks source link

estimating predicted values from GEE model #153

Open ParkvilleGeek opened 3 years ago

ParkvilleGeek commented 3 years ago

Hello

Not an issue with the fabulous easystats packages but I'm having problems generating and subsequently plotting estimated values from a GEE model using modelbased functions and see.

The GEE model has two covariates _fitgee <- gee( y ~ x + cov1+ cov2, data = df, id = ID)

parameters can display the model output

Parameter | Coefficient | SE | 95% CI | z | p

(Intercept) | 0.77 | 0.30 | [ 0.18, 1.36] | 2.54 | 0.011 x | 0.49 | 0.07 | [ 0.36, 0.62] | 7.24 | < .001 cov1 | 0.14 | 0.08 | [-0.02, 0.30] | 1.75 | 0.080 cov2 | 0.09 | 0.02 | [ 0.05, 0.13] | 4.53 | < .001

I've been following the vignettes but no success with get_predicted or predict

_> vizdata$Predicted <- get_predicted(fit_gee, vizdata) Error in eval(predvars, data, env) : object 'twinsex' not found In addition: Warning message: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type == : calling predict.lm() ...

Any suggestions?

Many thanks

@ParkvilleGeek

bwiernik commented 3 years ago

Can you give a full reproducible example? It looks like you might be trying to use the wrong dataset with your fitted model (ie, the model in your get_predicted() call has twin_sex as a predictor instead of cov1 and cov2).

ParkvilleGeek commented 3 years ago

Thanks for the quick reply and apologies for the confusion. I was trying to create a "general" example for the actual data.

Here's a reproducible example

fit_gee <- gee(y ~ x + age + sex, data = df, id = ID) Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27 running glm to get initial regression estimate (Intercept) x age sexmale 0.7694870 0.4876350 0.0940889 0.1430764

model_parameters(fit_gee) Parameter | Coefficient | SE | 95% CI | z | p

(Intercept) | 0.77 | 0.30 | [ 0.18, 1.36] | 2.54 | 0.011 x | 0.49 | 0.07 | [ 0.36, 0.62] | 7.24 | < .001 age | 0.09 | 0.02 | [ 0.05, 0.13] | 4.53 | < .001 sex [male] | 0.14 | 0.08 | [-0.02, 0.30] | 1.75 | 0.080

Showing profiled confidence intervals.

vizdata <- visualisation_matrix(df["x"]) vizdata$Predicted <- insight::get_predicted(fit_gee, vizdata) Error in eval(predvars, data, env) : object 'age' not found In addition: Warning message: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type == : calling predict.lm() ...

I have attached the df if you have some suggestions.

Many thanks

example.df.csv