[R] ANCOVA, Ops.factor, singular fit???
Marc Schwartz
MSchwartz at mn.rr.com
Sat May 20 15:29:30 CEST 2006
On Sat, 2006-05-20 at 08:36 +0200, Peter Dalgaard wrote:
> rebecca.sealfon at duke.edu writes:
>
> > I'm trying to perform ANCOVAs in R 1.14, on a Mac OS X, but I can't figure out
>
> ?! There's no version 1.14 of R.
Looking at the Mac page on CRAN, I suspect that this is the GUI version
number, rather than the R version number.
This has confused me as well in prior posts. I don't use a Mac, so am
unclear as to how this particular version number is obtained. Is there a
Help -> About type of menu on the Mac GUI where this value is displayed?
Not sure if this would be considered user error, or if the GUI is
unclear as to differing version numbering between R and the other
components on Macs.
> > what I am doing wrong. Essentially, I'm testing whether a number of
> > quantitative dental measurements (the response variables in each ANCOVA) show
> > sexual dimorphism (the sexes are the groups) independently of the animal's size
> > (the concomitant variable). I have attached a 13-column matrix as a data frame
This may be the problem. If the data source is a matrix, which can of
course only contain a single data type, the inclusion of a gender
column, which is presumably textual, will force all columns to text in
the matrix and then to factors in the data frame:
> ln1 <- 1:5
> ln2 <- 1:5
> sex <- c("Male", "Female", "Female", "Male", "Male")
> mat <- cbind(ln1, sex, ln2)
> mat
ln1 sex ln2
[1,] "1" "Male" "1"
[2,] "2" "Female" "2"
[3,] "3" "Female" "3"
[4,] "4" "Male" "4"
[5,] "5" "Male" "5"
> str(mat)
chr [1:5, 1:3] "1" "2" "3" "4" "5" "Male" "Female" "Female" "Male" ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:3] "ln1" "sex" "ln2"
Note that all columns in 'mat' are now character vectors.
> DF <- as.data.frame(mat)
> DF
ln1 sex ln2
1 1 Male 1
2 2 Female 2
3 3 Female 3
4 4 Male 4
5 5 Male 5
> str(DF)
`data.frame': 5 obs. of 3 variables:
$ ln1: Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5
$ sex: Factor w/ 2 levels "Female","Male": 2 1 1 2 2
$ ln2: Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5
Note that all columns are factors, the default behavior of converting
character vectors into a data frame.
Now the model with interactions:
> model <- lm(ln2 ~ sex * ln1, data = DF)
Warning message:
- not meaningful for factors in: Ops.factor(y, z$residuals)
> summary(model)
Call:
lm(formula = ln2 ~ sex * ln1, data = DF)
Residuals:
ALL 5 residuals are 0: no residual degrees of freedom!
Coefficients: (5 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3 NA NA NA
sexMale -2 NA NA NA
ln12 -1 NA NA NA
ln13 NA NA NA NA
ln14 3 NA NA NA
ln15 4 NA NA NA
sexMale:ln12 NA NA NA NA
sexMale:ln13 NA NA NA NA
sexMale:ln14 NA NA NA NA
sexMale:ln15 NA NA NA NA
Residual standard error: NA on 0 degrees of freedom
Multiple R-Squared: NA, Adjusted R-squared: NA
F-statistic: NA on 4 and 0 DF, p-value: NA
Warning message:
^ not meaningful for factors in: Ops.factor(r, 2)
The long output that you refer to is presumably the multitude of terms
and interactions at the various levels of the three factors.
How did you read in the data initially? You need to be careful to
maintain the data types, as Peter notes below. Reviewing the R
Import/Export Manual may be helpful.
HTH,
Marc Schwartz
> > (so far, so good). But then I tried to do this:
> >
> > >model<-lm(ln2~sex*ln1)
> >
> > or this:
> >
> > >model<-lm(ln2~sex+ln1)
> >
> > and got this:
> >
> > Warning message:
> > - not meaningful for factors in: Ops.factor(y, z$residuals)
> >
> > which I don't understand. (In my matrix, ln2 is the name of the second column,
> > a response variable, and ln1 is the name of the first column, a concomitant
> > variable. Sex is the rightmost column, indicating sex. The first 14 rows are
> > measurements for male individuals, and the next 13 rows are measurements for
> > female individuals.)
> >
> > The data output is bizarre, too--it's just so long, and everything begins with
> > "ln 11" or "ln 12". How can I fix this?
>
> My best guess is that you have a data error so that ln1 and ln2 are
> not read as numeric variables. Nonstandard codes for missing will do
> that to you, for instance.
>
More information about the R-help
mailing list