[R] SOLVED error in summary.Design

DAVID ARTETA GARCIA darteta001 at ikasle.ehu.es
Tue Apr 29 12:45:46 CEST 2008


Dear Frank and rest of list, please accept my apologies for not giving  
full details of my analysis in my previous email. I have been working  
on this problem and I think my error comes from the class of my  
variables and the way I defined the model, and I seemed to be able to  
solve it...

> d = datadist(VAR2,VAR3,VAR4,VAR5,VAR6,VAR7,VAR8)
> options(datadist="d")

but then I called the model on factors

> mymodel = lrm(factor(VAR1)~VAR2+factor(VAR3)+  
> factor(VAR4)+factor(VAR5)+factor(VAR6)+factor(VAR7)+factor(VAR8),  
> mydata, method="lrm.fit")

Storing the variables in mydata as factors and recomputing "d" solves  
the mistake

> VAR1 = factor(mydata$VAR1)
> VAR3 = factor(mydata$VAR3)
> VAR4 = factor(mydata$VAR4)
> VAR5 = factor(mydata$VAR5)
> VAR6 = factor(mydata$VAR6)
> VAR7 = factor(mydata$VAR7)
> VAR8 = factor(mydata$VAR8)

and

> VAR2 = mydata$VAR2

> dd = datadist(VAR2, VAR3,VAR4,VAR5,VAR6,VAR7,VAR8)
> options(datadist="dd")
> mymodel2 = lrm(VAR1~VAR2+VAR3+VAR4+VAR5+VAR6+VAR7+VAR8, method="lrm.fit")

This time, summary.Design() works


Thanks for the useful comments

David



Frank E Harrell Jr <f.harrell at vanderbilt.edu> ha escrito:

> DAVID ARTETA GARCIA wrote:
>> Dear list,
>>
>> after fitting an lrm with the Design package (stored as "mymodel")   
>> I try running a summary, but I get the following error:
>>
>> dim(mydata)
>> [1] 235   9
>>
>> names(mydata)
>> [1] "id"   "VAR1" "VAR2" "VAR3" "VAR4" "VAR5" "VAR6"  "VAR7" "VAR8"
>>
>> summary(mymodel)
>
> What is mymodel?  Please read the posting guide by providing a full
> reproducible example.  You can't expect people to help if you want to
> keep your code a secret.
>
>> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
>>  contrasts can be applied only to factors with 2 or more levels
>>
>> but,
>>
>> VAR1 is my dependent
>>> nlevels(factor(VAR1))
>> [1] 2
>
> This does not tell you about VAR1.  It tells you about VAR1 after
> converting it to a factor variable.
>
> Frank
>
>>
>> VAR2 is continuous
>>> summary(VAR2)
>>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>>   0.90    6.05    8.40   10.99   13.15   59.70
>>
>> and for the remaining variables...
>>
>>> nlevels(factor(VAR3))
>> [1] 2
>>> nlevels(factor(VAR4))
>> [1] 2
>>> nlevels(factor(VAR5))
>> [1] 3
>>> nlevels(factor(VAR6))
>> [1] 2
>>> nlevels(factor(VAR7))
>> [1] 2
>>> nlevels(factor(VAR8))
>> [1] 2
>>
>>
>> What I am missing?
>>
>> Thanks in advance,
>>
>> David
>>
>> ______________________________________________
>> 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.
>>
>
>
> -- 
> Frank E Harrell Jr   Professor and Chair           School of Medicine
>                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list