[R-sig-ME] factor / intiger

Sam Sam_Smith at me.com
Tue Aug 3 15:43:52 CEST 2010


Dear Dan,

Thanks for this, 

I was not working back from the AIC i was just unsure why they are different - in what way are they a different model?

If i have categorical predictors i should code them as factors in GLMM - correct?

Thanks

Sam
On 3 Aug 2010, at 14:40, Daniel Ezra Johnson wrote:

Dear Sam,

When the factor levels are numbers, you have to do:

> A <- as.factor(as.character(A))

Regarding your other question, it's an entirely different model, if
you treat the predictors as linear/numeric or as factors. You should
choose based on what the predictor(s) is/are, probably not working
backwards from the AIC.

Dan

On Tue, Aug 3, 2010 at 9:34 AM, Sam <Sam_Smith at me.com> wrote:
> Dear List
> 
> I have a excel spread sheet with 5 columns that contain categorical data. I have recoded them to numbers
> 
> A       B       C
> 0       0       0
> 1       1       1
> 2       2       2
> 3       3
> 4
> 5
> 
> etc
> 
> When i read it into R and do str(dataframe) i get -
> 
>  $ A       : int  1 1 1 1 1 1 1 1 1 1 ...
>  $ B    : int  1 1 1 1 1 1 1 1 1 1 ...
>  $ C       : int  0 0 0 0 0 0 0 0 0 0 ...
>  $ D    : int  0 0 0 0 0 0 0 0 0 0 ...
>  $ E : int  0 0 0 0 0 0 0 0 0 0 ...
> 
> I then realised they should probably be factors instead of integers so used as.factor to convert them -
> 
> A <- as.factor(A)
> 
> Now when i run the GLMM the AIC values are different from when they were integers, i have 2 questions
> 
> 1. Should i not have converted the categories to numbers in the excel spreadsheet before import.
> 
> 2. Why are the AIC values different when i use as.factor as opposed to keeping them as integers, and which approach is recommended?
> 
> Thanks
> 
> Sam
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> 

_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models




More information about the R-sig-mixed-models mailing list