r - "left join" the results of glm to original file if there are missings in the model outcome? -


after creating model glm

model <- glm(data$y ~ data$x * data$z) 

i need create dataset includes output of glm , original data further processing

newdata <- data.frame(                   data$id,                    data$y, #observed                    fitted(model), #expected                   resid(model),                   data$x,                   data$z,                   data$othervariable1,                   data$othervariable2,                   data$othervariable3                   ) 

this runs long glm produces many records data file has. if reason (mostly missing values) model data has less records join doesn't work:

error in data.frame(....): arguments has differents counts of rows: 21, 18

na.action = na.pass in order avoid missing values in glm didn't seem work either

is there way transport unique identifier glm output? or there fancy function?(i'm sure there ism don't find it)

this situation na.exclude made for. see details section of ?residuals.glm. residuals , fitted values contain na values if use na.exclude.

example using data @thomas answer:

fit1 = glm(y ~ x, data = dat) length(residuals(fit1)) [1] 90  fit2 = glm(y ~ x, data = dat, na.action = na.exclude) length(residuals(fit2)) [1] 100 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -