[R] latex.rms and models fit with Gls

Frank E Harrell Jr f.harrell at Vanderbilt.Edu
Sat May 29 05:06:33 CEST 2010


On 05/28/2010 05:31 PM, Dylan Beaudette wrote:
> On Friday 28 May 2010, Frank E Harrell Jr wrote:
>> On 05/28/2010 03:49 PM, Dylan Beaudette wrote:
>>> Hi,
>>>
>>> I have fit a model using the rms package with the Gls() function.
>>>
>>> Is there a way to get the model estimates, std errors, and p-values (i.e.
>>> what you get with print(fit)) into latex format?
>>>
>>> I have tried:
>>>
>>> f<- Gls(...)
>>> latex(f, file='')
>>>
>>> ... but I get the following error
>>>
>>> Error in replace.substring.wild(s, old, new, test = test, front = front,
>>> : does not handle>   1 * in old
>>>
>>> I think that this might have something to do with the fact that I fit the
>>> model with GLS. (?)
>
> Thanks for the quick reply Frank.
>
>> What is GLS?  I thought you fit the model with Gls.  And please follow
>> the posting guide instead of submitting only parts of lines of code.
>
> Right, that would have been helpful. I didn't want to paste in the enormous
> example from the Gls() manual page...
>
>> The latex method for a Gls object typesets the mathematical form of the
>> fitted model formula.
>
> OK. That would have been nice too, but why did I get the above error message?
> Lets recreate my data with an example:
>
> # fake data
> w<- rnorm(50)
> x<- rnorm(50)
> y<- rnorm(50)
> z<- rnorm(50)
> p<- runif(50)
> g<- rep(c('a','b'), each=25)
>
> # sprinkle in some NA
> w[sample(1:50, 4)]<- NA
>
> # fit data with similar correlation structure
> f<- Gls(p ~ y * x * (z + w), na.action='na.omit', cor=corCAR1(form= ~ z | g))
>
> # hmmm.... "Error in terms.default(f) : no terms component"

Thanks for the good example and sorry about the error.  I've posted a 
fix for Gls.  Use the following to override the current version with the 
fixed one:

source('http://biostat.mc.vanderbilt.edu/tmp/Gls.s')

I've also changed the default na.action to na.omit.  For some reason 
model.frame doesn't work with the output of the Hmisc package's more 
comprehensive na.delete function when used with Gls.

> latex(f, file='')
>
> The attached packages are:
> nlme_3.1-96     rms_3.0-0       Hmisc_3.8-0     survival_2.35-8
>
>
>> To get what you want:
>>
>> w<- nlme:::summary.gls(f)$tTable
>> w
>> latex(w, ....)
>
> Got it. Thanks-- this does exactly what I was looking for. I wonder if it
> might be worth the effort to include a small snippet on this in the manual
> pages...

done

Frank

>
> Cheers,
> Dylan
>
>
>> Frank
>>
>>> I am looking for a simple way to get a table of estimated coeficients
>>> without hand-making a table in a text editor for inclusion within a LATEX
>>> document.
>>>
>>> Thanks!
>
>
>


-- 
Frank E Harrell Jr   Professor and Chairman        School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list