[R] Simple question about function with glm

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon May 7 04:26:43 CEST 2007


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 
	summary(xmodel)
	confint(xmodel)

By
	print(summary(xmodel))
	print(confint(xmodel))

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-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Chung-hong Chan
Sent: Sunday, 6 May 2007 6:47 PM
To: r-help at stat.math.ethz.ch
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) {
	library(nortest)
	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?

Regards,
CH


--
"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
http://www.macgrass.com

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list