Mark Kimpel
2009-Oct-28 17:12 UTC
[R] how to model a numeric factor as a non-ordinal factor
I am analyzing an experiment in which time is a factor, represented by numbers indicating time since last treatment, but in this particular case there is no reason to think that time has a numeric meaning in the sense that 24 would be greater than 6. We have no idea which genes will be increasing or decreasing at different times. So I have the following model (to be applied over many genes): mod <- lm(gene.expression ~ Treatment + Time) If I wanted to just hack my way around this I could just paste a character to all of the times, but I'm curious as to the right way to do this. What would be the correct syntax or transformation? Would Time <- factor(as.character(Time)) do it? I want to make sure that it does not get coerced back to numeric. Thanks, Mark Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry Indiana University School of Medicine 15032 Hunter Court, Westfield, IN 46074 (317) 490-5129 Work, & Mobile & VoiceMail (317) 399-1219 Skype No Voicemail please [[alternative HTML version deleted]]
Peter Dalgaard
2009-Oct-28 17:34 UTC
[R] how to model a numeric factor as a non-ordinal factor
Mark Kimpel wrote:> I am analyzing an experiment in which time is a factor, represented by > numbers indicating time since last treatment, but in this particular case > there is no reason to think that time has a numeric meaning in the sense > that 24 would be greater than 6. We have no idea which genes will be > increasing or decreasing at different times. > > So I have the following model (to be applied over many genes): > > mod <- lm(gene.expression ~ Treatment + Time) > > If I wanted to just hack my way around this I could just paste a character > to all of the times, but I'm curious as to the right way to do this. > > What would be the correct syntax or transformation? Would Time <- > factor(as.character(Time)) do it? I want to make sure that it does not get > coerced back to numeric.Just factor(Time) should do it. (If you do as.character first, you get the levels sorted alphabetically, which you'd probably rather not). -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
David Winsemius
2009-Oct-28 17:44 UTC
[R] how to model a numeric factor as a non-ordinal factor
So is this factor ordered or not. Is it just in your model to create unordered strata? What does the Time variable look like now? summary(Time) Depending on how Time and Treatment are associated with the subjects you may choose different options. And are they sitting in a dataframe? -- David. On Oct 28, 2009, at 1:12 PM, Mark Kimpel wrote:> I am analyzing an experiment in which time is a factor, represented by > numbers indicating time since last treatment, but in this particular > case > there is no reason to think that time has a numeric meaning in the > sense > that 24 would be greater than 6. We have no idea which genes will be > increasing or decreasing at different times. > > So I have the following model (to be applied over many genes): > > mod <- lm(gene.expression ~ Treatment + Time) > > If I wanted to just hack my way around this I could just paste a > character > to all of the times, but I'm curious as to the right way to do this. > > What would be the correct syntax or transformation? Would Time <- > factor(as.character(Time)) do it? I want to make sure that it does > not get > coerced back to numeric. > > Thanks, > > Mark > > Mark W. Kimpel MD ** Neuroinformatics ** Dept. of Psychiatry > Indiana University School of Medicine > > 15032 Hunter Court, Westfield, IN 46074 > > (317) 490-5129 Work, & Mobile & VoiceMail > (317) 399-1219 Skype No Voicemail please > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.David Winsemius, MD Heritage Laboratories West Hartford, CT