I have a data like below, and trying to write a soccer prediction with R.
Div Date HomeTeam AwayTeam FTHG FTAG FTR HTHG
Length:2184 Length:2184 Length:2184 Length:2184 Min. :0.000 Min. :0.000 Length:2184 Min. :0.000
Class :character Class :character Class :character Class :character 1st Qu.:1.000 1st Qu.:0.000 Class :character 1st Qu.:0.000
Mode :character Mode :character Mode :character Mode :character Median :1.000 Median :1.000 Mode :character Median :0.000
Mean :1.539 Mean :1.192 Mean :0.668
3rd Qu.:2.000 3rd Qu.:2.000 3rd Qu.:1.000
Max. :7.000 Max. :7.000 Max. :5.000
FTR contains H(ome), A(way), D(raw). So it is character in data.frame.
While I am using this code below:
glm.fits = glm(FTR ~ .,data=alldata,family=binomial)
I am getting this error:
Error in contrasts<-
(*tmp*
, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
How can I solve it?
edit: I changed the FTR to vector, still not working
Solution: I decided to change my FTR from A,H,D to A(away), NA(not away). I guess this will solve the problem.