Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Is there a way to use the base R rug function when plotting gam predictions for categorical predictor

$
0
0

I have run some gams in r and am in the process of plotting the predicted response on the y axis and predictors on the x. I have used rug() to indicate the amount of data points on all plots with continuous predictors. I am now in the process where I am doing the same prediction plots but with categorical (factor) predictors. The rug() function now does not work. I have the following data and code:

BFRT_FRC_L  <-  c('0',  '1',    '2',    '3',     
'4',    '5',    '6')
fit1    <-  c(4.794081, 4.024341,   3.747784,    
3.690677,   1.991833,   5.28066,    6.82015)
se.fit1 <-  c(0.5903663,    0.5822973, 
0.5809198,  0.5825511,  0.5999183,  0.5852767,   
0.5937017)
b   <-  c(22,   136,    145,    76, 36, 18, 3)
plot(y=exp(fit1), x=(as.factor(BFRT_FRC_L)), type="l", lwd=2, 
xlab="BFRT_FRC",
ylab="Predicted Attendance", ylim = c(0,500))
points(y=exp(fit1+se.fit1), x=BFRT_FRC_p, lwd=1, lty=2)
points(y=exp(fit1-se.fit1), x=BFRT_FRC_p, lwd=1, lty=2)
rug(x = as.integer(b))

enter image description here

where it should look something like this from the gam partial plots:

enter image description here

Any help in getting the rug to work would be appreciated.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>