in R evaluate fit like a formula -


in r, if have fit

x <- c(0,var_moda,1) b <- c(v1, v2, v3) p2_fit <- lm( b ~ poly(x, 2)) 

how can use fit formula?

maybe

p2_fit(0.5) 

do note newdata argument of predict.lm requires

an optional data frame in variables predict. if omitted, fitted values used.

you supplied length 1 numeric vector. r should have thrown error x not being found , if claim did in comment. returning fitted values happens when forget supply newdata.

you want like

predict(p2_fit, newdata = data.frame(x = 0.5)) 

the name of x important. must match variable(s) on right hand side of formula.


Comments