Plotting log transformed predicted values from lme

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Plotting log transformed predicted values from lme

Duststorm
Hi,

I am performing meta-regression using linear mixed-effect model with the
lme() function  that has two fixed effect variables;one as a log
transformed variable (x)  and one as factor (y) variable, and two nested
random intercept terms.

I want to save the predicted values from that model and show the log curve
in a plot ; predicted~log(x)

mod<-lme(B~log(x)+as.factor(y), random=~1|cohort/Study,
weights=varFixed(~I(SE^2)), na.action=na.omit, data=subset(meta),
          control = lmeControl(sigma = 1, apVar = FALSE))
summary(mod)

newdat <- data.frame(x=seq(min(meta$x), max(meta$x),,118))  # I have 118
observations. #How do I add the factor variable to my newdat?
newdat$pred <- predict(mod, newdat,level = 0,type="response")

plot(B ~ x, data=meta)
lines(B ~ x, data=newdat)

Can you please assist me ?

Thank you!

Alina

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting log transformed predicted values from lme

Michael Dewey-3
Dear Alina

If I understand you correctly you cannot just have a single predicted
curve but one for each level of your factor.

On 09/08/2017 16:24, Alina Vodonos Zilberg wrote:

> Hi,
>
> I am performing meta-regression using linear mixed-effect model with the
> lme() function  that has two fixed effect variables;one as a log
> transformed variable (x)  and one as factor (y) variable, and two nested
> random intercept terms.
>
> I want to save the predicted values from that model and show the log curve
> in a plot ; predicted~log(x)
>
> mod<-lme(B~log(x)+as.factor(y), random=~1|cohort/Study,
> weights=varFixed(~I(SE^2)), na.action=na.omit, data=subset(meta),
>           control = lmeControl(sigma = 1, apVar = FALSE))
> summary(mod)
>
> newdat <- data.frame(x=seq(min(meta$x), max(meta$x),,118))  # I have 118
> observations. #How do I add the factor variable to my newdat?
> newdat$pred <- predict(mod, newdat,level = 0,type="response")
>
> plot(B ~ x, data=meta)
> lines(B ~ x, data=newdat)
>
> Can you please assist me ?
>
> Thank you!
>
> Alina
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
> ---
> This email has been checked for viruses by AVG.
> http://www.avg.com
>
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting log transformed predicted values from lme

Duststorm
Thank you Michael,
Curves for each level of the factor sounds  very interesting,
Do you have a suggestion how to plot them?

Thank you!
Alina

*Alina Vodonos Zilberg*




On Thu, Aug 10, 2017 at 7:39 AM, Michael Dewey <[hidden email]>
wrote:

> Dear Alina
>
> If I understand you correctly you cannot just have a single predicted
> curve but one for each level of your factor.
>
>
> On 09/08/2017 16:24, Alina Vodonos Zilberg wrote:
>
>> Hi,
>>
>> I am performing meta-regression using linear mixed-effect model with the
>> lme() function  that has two fixed effect variables;one as a log
>> transformed variable (x)  and one as factor (y) variable, and two nested
>> random intercept terms.
>>
>> I want to save the predicted values from that model and show the log curve
>> in a plot ; predicted~log(x)
>>
>> mod<-lme(B~log(x)+as.factor(y), random=~1|cohort/Study,
>> weights=varFixed(~I(SE^2)), na.action=na.omit, data=subset(meta),
>>           control = lmeControl(sigma = 1, apVar = FALSE))
>> summary(mod)
>>
>> newdat <- data.frame(x=seq(min(meta$x), max(meta$x),,118))  # I have 118
>> observations. #How do I add the factor variable to my newdat?
>> newdat$pred <- predict(mod, newdat,level = 0,type="response")
>>
>> plot(B ~ x, data=meta)
>> lines(B ~ x, data=newdat)
>>
>> Can you please assist me ?
>>
>> Thank you!
>>
>> Alina
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ---
>> This email has been checked for viruses by AVG.
>> http://www.avg.com
>>
>>
>>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting log transformed predicted values from lme

Michael Dewey-3


On 10/08/2017 13:48, Alina Vodonos Zilberg wrote:
> Thank you Michael,
> Curves for each level of the factor sounds  very interesting,
> Do you have a suggestion how to plot them?
>

Make your newdata matrix N times longer where your factor has N levels
and replicate your log(x) down one column and repeat each factor level
118 times.

Then plot the predicted values using lines separately for each subset of
data corresponding to a level of your factor (choosing a different line
type)

> Thank you!
> Alina
>
> *Alina Vodonos Zilberg*
>
>
>
>
> On Thu, Aug 10, 2017 at 7:39 AM, Michael Dewey <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Dear Alina
>
>     If I understand you correctly you cannot just have a single
>     predicted curve but one for each level of your factor.
>
>
>     On 09/08/2017 16:24, Alina Vodonos Zilberg wrote:
>
>         Hi,
>
>         I am performing meta-regression using linear mixed-effect model
>         with the
>         lme() function  that has two fixed effect variables;one as a log
>         transformed variable (x)  and one as factor (y) variable, and
>         two nested
>         random intercept terms.
>
>         I want to save the predicted values from that model and show the
>         log curve
>         in a plot ; predicted~log(x)
>
>         mod<-lme(B~log(x)+as.factor(y), random=~1|cohort/Study,
>         weights=varFixed(~I(SE^2)), na.action=na.omit, data=subset(meta),
>                   control = lmeControl(sigma = 1, apVar = FALSE))
>         summary(mod)
>
>         newdat <- data.frame(x=seq(min(meta$x), max(meta$x),,118))  # I
>         have 118
>         observations. #How do I add the factor variable to my newdat?
>         newdat$pred <- predict(mod, newdat,level = 0,type="response")
>
>         plot(B ~ x, data=meta)
>         lines(B ~ x, data=newdat)
>
>         Can you please assist me ?
>
>         Thank you!
>
>         Alina
>
>                 [[alternative HTML version deleted]]
>
>         ______________________________________________
>         [hidden email] <mailto:[hidden email]> mailing list
>         -- To UNSUBSCRIBE and more, see
>         https://stat.ethz.ch/mailman/listinfo/r-help
>         <https://stat.ethz.ch/mailman/listinfo/r-help>
>         PLEASE do read the posting guide
>         http://www.R-project.org/posting-guide.html
>         <http://www.R-project.org/posting-guide.html>
>         and provide commented, minimal, self-contained, reproducible code.
>
>         ---
>         This email has been checked for viruses by AVG.
>         http://www.avg.com
>
>
>
>     --
>     Michael
>     http://www.dewey.myzen.co.uk/home.html
>     <http://www.dewey.myzen.co.uk/home.html>
>
>
>
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
> Virus-free. www.avg.com
> <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>
>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Plotting log transformed predicted values from lme

PaulJohnson32gmail
In reply to this post by Duststorm
In the rockchalk package, I have a function called newdata that will help
with this. Plenty of examples. Probably my predictOmatic function will just
work. Motivation is in the vignette.

Paul Johnson
University of Kansas

On Aug 9, 2017 11:23 AM, "Alina Vodonos Zilberg" <[hidden email]>
wrote:

> Hi,
>
> I am performing meta-regression using linear mixed-effect model with the
> lme() function  that has two fixed effect variables;one as a log
> transformed variable (x)  and one as factor (y) variable, and two nested
> random intercept terms.
>
> I want to save the predicted values from that model and show the log curve
> in a plot ; predicted~log(x)
>
> mod<-lme(B~log(x)+as.factor(y), random=~1|cohort/Study,
> weights=varFixed(~I(SE^2)), na.action=na.omit, data=subset(meta),
>           control = lmeControl(sigma = 1, apVar = FALSE))
> summary(mod)
>
> newdat <- data.frame(x=seq(min(meta$x), max(meta$x),,118))  # I have 118
> observations. #How do I add the factor variable to my newdat?
> newdat$pred <- predict(mod, newdat,level = 0,type="response")
>
> plot(B ~ x, data=meta)
> lines(B ~ x, data=newdat)
>
> Can you please assist me ?
>
> Thank you!
>
> Alina
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Loading...