From: <Bill.Venables_at_csiro.au>

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

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

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.

-----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. ______________________________________________ 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.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 https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*