[R] cross validation with variables which have one factor only

2014-03-04 Thread Maik Rehnus

   Dear R-team
   I  did a model selection by AIC which explain me the habitat use of my
   animals   in   six   different   study   sites  (See  attached  files:
   cross_val_CORINE04032014.csv and cross_val_CORINE04032014.r). Sites were
   used as random factor because they are distributed over the Alps and so very
   different. In this way I also removed variables which exist in one study
   area  only  to  do the model selection. In next, I tried to do a cross
   validation with the estimated best model for its prediction per site. That
   means I used model of five sites togehther against the remaining site. In
   this step I received an error:

val_10_fold_minger - cv.glm(data= minger, glmfit = best_model_year, K =
   10)
   Error in `contrasts-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
 contrasts can be applied only to factors with 2 or more levels

   So for some of the model variables used in the model formula below there are
   actually  not  two factor levels (example=C324F where absence :153 but
   presence:  0 )
   best_model_year - glm(dung1_b ~ C231F+C324F+C332F, family=binomial(logit),
   minger)
   Does somebody know is there a possibility in cross validation methods which
   can deal with variables which have one factor only?
   Kindly

   Maik
__
R-help@r-project.org mailing list
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.


[R] confidence bands for a quasipoisson glm

2010-09-11 Thread Maik Rehnus
Dear all,

I have a quasipoisson glm for which I need confidence bands in a graphic:

gm6 - glm(num_leaves ~  b_dist_min_new, family = quasipoisson, data = beva)
summary(gm6)

library('VIM')
b_dist_min_new - as.numeric(prepare(beva$dist_min, scaling=classical, 
transformation=logarithm)).

My first steps for the solution are following:

range(b_dist_min_new)
x - seq(-1.496, 1.839, by=0.01)  
newdat - data.frame(b_dist_min_new=x)
y - predict(gm6, newdata=newdat, type=response)
plot(x,y, type=l, ylim=c(0,15), lty=2, xlab=Distance [scaled log.], 
ylab=Number of used plant, las=1)

ilogit-function(x) exp(x)/(1 + exp(x))
logit -function(x) log(x/(1 - x))

newdat$logitpred - predict(gm6, newdata=newdat, type=link)   
newdat$sepred - predict(gm6, newdata=newdat, type=link, se.fit=TRUE)$se.fit  
newdat$logitlower - newdat$logitpred-1.96 * newdat$sepred 
newdat$logitupper - newdat$logitpred+1.96 * newdat$sepred
newdat$upper - ilogit(newdat$logitupper)  
newdat$lower - ilogit(newdat$logitlower)
lines(x, newdat$lower, lty=3)  
lines(x, newdat$upper, lty=3).

In this way I could find a positive correlation. But my created confidence 
bands on the graph don't touch my regression line. Could it be a technical 
problem or is it a mistake in the calculation?

I am new here and I hope you can help to solve my problem. I could not find any 
answers for quasipoisson glm on internet.

Best regards

Maik



  
-- 
GMX DSL SOMMER-SPECIAL: Surf  Phone Flat 16.000 für nur 19,99 Euro/mtl.!*

__
R-help@r-project.org mailing list
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.