title: mgcv: can I drop a level for factor 'by' variable?
body: <h1>the story:</h1>
  <p>I'm facing a problem in gam where only 2 input-variable should be considered:</p>
  <p>x = relative price (%) the customer paid for the product given the entry price for the club</p>
  <p>b = binary, if the customer has to pay the product (VIPs get it for free)</p>
  <p>the output-variable is</p>
  <p>y = if the customer took the product</p>
  <p>and this sims the data:</p>
  <pre><code>require(mgcv)
  require(data.table)
  set.seed(2017)
  y &lt;- sample(c(0, 1), 100, replace=T)
  x &lt;- rgamma(100, 3, 3)
  b &lt;- as.factor(ifelse(x&lt;.5, 0, 1))
  dat &lt;- as.data.table(list(y=y, x=x, b=b))
  dat[b==&quot;0&quot;,x:=0]
  plot(dat$x, dat$y, col=dat$b)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/9aEwu.png" rel="nofollow noreferrer">relative price</a></p>
  <p>as you can see in the plot, customers who hadn't pay for the product have a relative price for the product at 0%, others have the relative prices between .5% and 3.5%</p>
  <h1>here comes the problem:</h1>
  <p>I want to model one dummy effect for b and a smooth effect for x (certainly only for those who has to pay), so I use b also as a by-variable in x:</p>
  <pre><code>mod &lt;- bam(y~b+s(x, by=b), data=dat, family=binomial(link=&quot;logit&quot;))
  summary(mod)
  par(mfrow=c(1,2))
  plot(mod)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DFfKv.png" rel="nofollow noreferrer">smooth effects</a></p>
  <h1>my question is:</h1>
  <p>a. why can you still see rug by s(x, b=1) at 0%, wouldn't it makes more sense if mgcv only consider those who has to pay? does this problem has s.th to do with the knots?</p>
  <p>b. as you can see in the summary, the dummy effect is estimated as NA, this might has to do with the fact that the information of b was totally used in as by-variable in s(x) so the dummy b itself has no more information to give? how can I overcome this problem, in other words: is there a option to model a smooth term only for a subset of the data and make mgcv actually only use this subset to fit?</p>