Skip to content
Prev 293451 / 398503 Next

warning with glm.predict, wrong number of data rows

carol white <wht_crl <at> yahoo.com> writes:
training set in glm and the second as
message:?
[snip]

The warning correctly diagnoses the problem.

The posting guide asks for a 'reproducible example', but you did not give us one.

There is one below. 

Note what happens when predict() tries to reconstruct the variable 'x[1:4]'
as dictated by the formula.

How many elements can 'x[1:4]' have when newdata has (say) nrowsNew?

Use the subset argument to select a subset of observations.
Call:  glm(formula = y[1:4] ~ x[1:4], family = binomial)

Coefficients:
(Intercept)       x[1:4]  
 -1.110e-16    0.000e+00  

Degrees of Freedom: 3 Total (i.e. Null);  2 Residual
Null Deviance:      5.545 
Residual Deviance: 5.545        AIC: 9.545
1             2             3             4 
-1.110223e-16 -1.110223e-16            NA            NA 
Warning message:
'newdata' had 2 rows but variable(s) found have 4 rows
1             2             3             4 
-1.110223e-16 -1.110223e-16 -1.110223e-16 -1.110223e-16 
Warning message:
'newdata' had 5 rows but variable(s) found have 4 rows
HTH,

Chuck

[rest deleted]