0
votes

I am using the data in Mtcars and need to produce a 3 column table that has the name of the vehicle in row 1, the probability of an automatic transmission in 2 and the value of AM in column 3 (automatic,manual). I have turned am, carb, gear, vs, and cyl into factors.

The table below works well but it gives me 0,1 for the values of AM

table(rownames(mtcars),mtcars$am)

I have attempted to add a third column using the glm

Predicting_am <-glm(am ~ carb+mpg+disp,
                    data = mtcars, 
                    family = "binomial")
Probofam <- predict(Predicting_am,
                    mtcars,type = 'response')
table(rownames(mtcars),mtcars$am,Probofam)

this gives me an ugly scattered situation and it needs to be three colums showing the name of the car, the probability, and the value of am(automatic or manual)

Please help.

1

1 Answers

1
votes

I think you should construct a dataframe.

result <- data.frame(Name = rownames(mtcars), 
                     am = mtcars$am, 
                     Probofam, row.names = NULL)
result

#                  Name am    Probofam
#1            Mazda RX4  1 0.804687472
#2        Mazda RX4 Wag  1 0.804687472
#3           Datsun 710  1 0.274468184
#4       Hornet 4 Drive  0 0.108778583
#5    Hornet Sportabout  0 0.064571610
#6              Valiant  0 0.020669417
#7           Duster 360  0 0.058593597
#8            Merc 240D  0 0.730144342
#9             Merc 230  0 0.530129116
#10            Merc 280  0 0.598268065
#...
#...