tjhelton
tjhelton

Reputation: 1

How to only return a single predicted value when using multiple regression in R

I am having an issue where I get hundreds of results when trying to predict a single result in R. Any suggestions on how I could resolve this issue would be extremely helpful.

logwage <- log(wage_data$wage, 10)

mlogwage <- lm(logwage ~ occupation + education + experience + age + south,
               data = wage_data)

newlogdata <- data.frame(occupation= "Sales", 
                         education = 16, 
                         experience = 10,
                         age = 45, 
                         south = "Yes", 
                         data = logwage)

predict(mlogwage,
        data = newlogdata, 
        interval = "confidence")

Upvotes: 0

Views: 535

Answers (1)

Len Greski
Len Greski

Reputation: 10855

Absent a reproducible example it is difficult to reproduce the error. Therefore, here is an example illustrating how to predict a single observation using the mtcars data set.

# build a multiple regression model 
aModel <- lm(mpg ~ am + disp + wt,data = mtcars)

# create data frame containing indepdendent variables for 
# a single observation 
aCar <- data.frame(am = 1,disp = 288,wt = 3.21)

predict(aModel,aCar,interval = "confidence")

...and the output:

> predict(aModel,aCar,interval = "confidence")
       fit      lwr      upr
1 19.20009 16.88843 21.51175
>

Upvotes: 1

Related Questions