[R] How to run a glm using one factor in a dichotomous categorical variable
Charles Thuo
tcmuigai at gmail.com
Wed Jul 1 06:22:46 CEST 2015
am running a glm to model the number of accidents that result from diesel
or petrol cars.
How can i run a glm that on only one factor i.e. diesel only.
require(CASdatasets)
data(freMTPL2freq)
CONTRACTS<-
data.frame(freMTPL2freq$IDpol,freMTPL2freq$ClaimNb,freMTPL2freq$Exposure,freMTPL2freq$VehPower,freMTPL2freq$VehAge,freMTPL2freq$DrivAge,
freMTPL2freq$VehBrand,freMTPL2freq$VehGas,freMTPL2freq$Region,freMTPL2freq$Density)
colnames(CONTRACTS)<-
c("IDpol","ClaimNb","Exposure","VehPower","VehAge","DrivAge","VehBrand","VehGas","Region","Density")
CONTRACTS.f<-CONTRACTS
vY<- CONTRACTS.f$ClaimNb
head(vY)
vE<- CONTRACTS.f$Exposure
head(vE)
X1<-CONTRACTS.f$VehGas;head(X1)
tapply(vY,X1,sum)
tapply(vY,X1,sum)/tapply(vE,X1,sum)
df<- data.frame(vY,vE,X1);head(df);tail(df)
regpoislog<- glm(vY~0+X1+offset(log(vE)),data=df,family=poisson(link="log"))
coef(regpoislog)
X1Diesel X1Regular
-2.327388 -2.267530
Kindly assist
[[alternative HTML version deleted]]
More information about the R-help
mailing list