[R] GAM with binary predictors

Thierry Onkelinx th|erry@onke||nx @end|ng |rom |nbo@be
Thu Feb 16 10:39:22 CET 2023


Dear Sacha,

use glm() in this case. I'd rather code the covariable as TRUE / FALSE or
as a factor.

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx using inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////

<https://www.inbo.be>


Op za 11 feb. 2023 om 18:35 schreef varin sacha via R-help <
r-help using r-project.org>:

> 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)
> ########################
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list