Marginal Effect with ggefects package

Hi,

The command "predict <- ggpredict(fit_tw1, terms = "pko_dummy")" does not work and it gives me the following error "Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor as.factor(pa_dummy) has new level 0.0906593406593407".
Can you help me?

Model: (The Model has fixed effects for countries (cown) and years (year)
fit_tw1 <- lm(parl_wom.per ~ as.factor(pko_dummy)*as.factor(pa_dummy) + as.factor(cown) + as.factor(year) + female_pko.per + lf_wom.per + ss.per + fdi.per + jud_ind.per + polity + as.factor(intensity_level) + as.factor(cons_ref),
data = subset(data9, rownames!="639"))

Reproducible example of the dataset (I apologise but I don't know how to make it as presentable as possible):

structure(list(cown = c(432, 432, 432, 432, 432, 432, 432, 432,
432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432, 432,
432, 432, 432, 432, 432, 432, 432, 432, 433, 433, 433, 433, 433,
433, 433, 433, 433, 433, 433), year = c(1990, 1991, 1992, 1993,
1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
2016, 2017, 2018, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
1998, 1999, 2000), intensity_level = c(1, 1, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0,
1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1), pa_dummy = c(0, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), pko_dummy = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), parl_wom.per = c(NA,
NA, 0.023, 0.023, 0.023, 0.023, 0.023, 0.122449, 0.122449, 0.122449,
0.122449, 0.122449, 0.1020408, 0.1020408, 0.1020408, 0.1020408,
0.1020408, 0.1020408, 0.1020408, 0.1020408, 0.1020408, 0.1020408,
0.1020408, NA, 0.0952381, 0.0884354, 0.0884354, 0.0884354, 0.0884354,
0.125, 0.125, 0.125, 0.117, 0.117, 0.117, 0.117, 0.1166667, 0.1214286,
0.1214286, 0.1214286), exe_wom.per = c(0.0588235, 0.1052632,
0.0526316, 0.0952381, 0.1111111, 0.0555556, 0.125, 0.1176471,
0.2608696, 0.2727273, 0.45, 0.4210526, 0.15, 0.15, 0.15, 0.1923077,
0.1923077, 0.1923077, 0.1851852, 0.1785714, 0.1785714, 0.125,
0.125, 0.1212121, 0.1333333, 0.1034483, 0.1666667, NA, NA, 0.0909091,
0.0909091, 0.0833333, 0.0833333, 0.0833333, 0.08, 0.08, 0.08,
0.0769231, 0.12, 0.1923077), gender_mean = c(0, 0, 1.75, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), female_pko.per = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, NA, 0.0155396288185458, 0.0198700449844285, 0.0227539964724656,
0.0263693147521193, NA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), lf_wom.per = c(0.60855,
0.60834, 0.6082, 0.60815, 0.6082, 0.60838, 0.60806, 0.60798,
0.60804, 0.60811, 0.60813, 0.60782, 0.60752, 0.60725, 0.60701,
0.60681, 0.60616, 0.60564, 0.60525, 0.60495, 0.60476, 0.60416,
0.60378, 0.60357, 0.6035, 0.61401, 0.59751, 0.58084, 0.58122,
0.32197, 0.32252, 0.32311, 0.32382, 0.32476, 0.326, 0.32674,
0.32778, 0.32903, 0.33034, 0.33161), ss.per = c(0.0679798984527588,
0.0723097991943359, 0.0827134037017822, 0.0837932968139648, 0.0957365036010742,
0.107322397232056, 0.112752199172974, 0.122838802337646, 0.133676099777222,
0.151076498031616, 0.174537200927734, NA, NA, 0.221253795623779,
0.239939594268799, 0.25832540512085, 0.277074604034424, 0.303055400848389,
0.33731990814209, 0.36671989440918, 0.392860984802246, 0.412325592041016,
NA, 0.418176689147949, 0.440181694030762, 0.417201385498047,
0.429929809570313, 0.415231399536133, 0.410272789001465, 0.153009004592896,
NA, 0.157048902511597, NA, NA, NA, 0.148124704360962, 0.145516901016235,
0.144128198623657, 0.151649703979492, 0.157028903961182), fdi.per = c(0.0021364,
0.0004424, -0.0077276, 0.001441, 0.0083661, 0.0411724, 0.009786,
0.0275705, 0.0032724, 0.0090061, 0.0203215, 0.0602065, -0.0031506,
0.0153489, 0.015555, 0.0256452, 0.0214593, 0.0252638, 0.0270809,
0.0631946, 0.0347613, 0.0427966, 0.0319775, 0.023247, 0.010026,
0.0210164, 0.0253981, 0.0364033, 0.0273605, 0.0076977, -0.0010407,
0.0027521, -0.0001102, 0.0132834, 0.0050067, 0.0021275, 0.0295971,
0.0109299, 0.0245246, 0.0135774), polity = c(-7, NA, 4, 4, 4,
4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, NA, 5, 5,
5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8), cons_ref = c(0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), jud_ind.per = c(0.476311308991478,
0.523786338536123, 0.557528417528326, 0.548066004702523, 0.548066004702523,
0.548066004702523, 0.548066004702523, 0.548066004702523, 0.548066004702523,
0.548066004702523, 0.548066004702523, 0.548066004702523, 0.548066004702523,
0.548066004702523, 0.548066004702523, 0.539288342106394, 0.539288342106394,
0.548066004702523, 0.539288342106394, 0.539288342106394, 0.539288342106394,
0.539288342106394, 0.539288342106394, 0.441303778744769, 0.441303778744769,
0.441303778744769, 0.454484089601846, 0.475808513448738, 0.466786677280237,
0.47910174486299, 0.490670507519414, 0.490670507519414, 0.47910174486299,
0.47910174486299, 0.481243860752709, 0.481993613513707, 0.481993613513707,
0.481993613513707, 0.481993613513707, 0.481993613513707), gender_art = c(0,
0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), rownames = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
"36", "37", "38", "39", "40")), row.names = c(NA, 40L), class = "data.frame")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.