[R] GAM with binary predictors
varin sacha
v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sat Feb 11 18:34:33 CET 2023
Dear R-experts,
I am trying to fit a GAM with 2 binary predictors (variables coded 0,1). I guess I cannot just smooth binary variables. By the way I code them as 0=no,1=yes, then mgcv will think those variables are numeric.
I have tried to change 0 and 1 in no and yes. It does not work.
How to solve my problem. Here below my toy example. Many thanks.
Best,
Sacha
########################
y=c(0.02,0.1,0.04,0.07,0.09,0.1,0.054,0.076,0.0897,0.09,0.1,0.86,0.74,0.53,0.35,0.67,0.63,0.95,0.72,0.85)
x1=c(1,0,0,1,1,0,0,1,0,1,1,1,0,1,0,0,0,1,0,0)
x2=c(0,0,1,1,0,1,1,0,0,1,1,1,0,0,1,0,0,1,1,0)
library(mgcv)
reg = gam(y ~ s(x1) +s(x2), family=binomial(link="logit"))
summary(reg)
########################
########################
y=c(0.02,0.1,0.04,0.07,0.09,0.1,0.054,0.076,0.0897,0.09,0.1,0.86,0.74,0.53,0.35,0.67,0.63,0.95,0.72,0.85)
x1=c("yes","no","no","yes","yes","no","no","yes","no","yes","yes","yes","no","yes","no","no","no","yes","no","no")
x2=c("no","no","yes","yes","no","yes","yes","no","no","yes","yes","yes","no","no","yes","no","no","yes","yes","no")
library(mgcv)
reg = gam(y ~ s(x1) +s(x2), family=binomial(link="logit"))
summary(reg)
########################
More information about the R-help
mailing list