Re: [R] Simple question about function with glm

From: <>
Date: Mon, 07 May 2007 12:26:43 +1000

There is a statistical problem and a code problem.

The statistical problem is that if your 'x' has a mean that depends non-trivially on predictors, then you would not expect its distribution ignoring predictors to be normal. You would expect the residuals after modelling to be normal. Basically you cannot sensibly test normality of the response before you fit the model. It's a very common mistake, even if rather an obvious one.

The code problem is that, do you really know whether your models have been fitted or not? The 'summary(xmodel)' part of your function below will not print anything out, so if you were expecting something from that you would be disappointed.

You might try replacing



But this is not really a very good paradigm in genera.

Finally, I'm a bit puzzled why you use glm() when the simpler lm() would have done the job. You are fitting a linear model and do not need the extra paraphernaila that generalized linear models require.

Bill Venables.

-----Original Message-----
[] On Behalf Of Chung-hong Chan Sent: Sunday, 6 May 2007 6:47 PM
Subject: [R] Simple question about function with glm

Dear all,

I coded a function called u.glm

u.glm <- function (x,ahi,age,bmiz,gender) {

	lil.rslt <- lillie.test(x)
	if (lil.rslt$p.value >0.05)

cat("Logtrans=0, lillie=",lil.rslt$p.value,"\n") xmodel<-glm(x~ahi+age+bmiz+as.factor(gender)) summary(xmodel) confint(xmodel) } else
cat("Logtrans=1, lillie=",lil.rslt$p.value,"\n") xmodel<-glm(x~ahi+age+bmiz+as.factor(gender)) summary(xmodel) confint(xmodel) }


Basically I just want to test the response variable for normality before modeling.
When I try to use this function, it can do the lillie's test but failed to do the glm.
What's wrong with my code?


"The scientists of today think deeply instead of clearly. One must be
sane to think clearly, but one can think deeply and be quite insane."
Nikola Tesla

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 07 May 2007 - 02:32:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 May 2007 - 04:31:11 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.