[R] Problem using predict() to draw lines() if predictor variable is logged on the fly

Adams, Jean jvadams at usgs.gov
Thu Oct 2 23:07:00 CEST 2014


You will have better luck getting replies to your post if you provide code
that we can run.  In other words, provide some small example data instead
of referring to your data frame that we have no access to.  You can use the
output from dput() to provide a subset of your data frame to the list.

dput(mydataframe[1:50, ])

Jean

On Thu, Oct 2, 2014 at 11:12 AM, <mtb954 at gmail.com> wrote:

> Hello,
>
> I am plotting glms with logged predictors. I would like to define the
> logged variables "on the fly" rather than hard coding them into my
> dataframe.
>
> This code (with hard-coded logged variables) works just fine:
>
> xx<-seq(-2,.5,by=0.1); lines(xx,predict(power,list(LogArKm00=xx),type=
> "response"),col="black",lwd=2,lty=1) #LogArKm00 is a variable in my
> dataframe
>
> but my attempt to define them "on the fly" doesn't work (see error below):
>
> plot(log(WbAb,10)~log(ArKm00,10),data=dat) #power model
>
> xx<-seq(-2,.5,by=0.1); lines(xx,predict(power,list(log(ArKm00,10)=xx),type=
> "response"),col="black",lwd=2,lty=1) #trying to log the variable "on the
> fly"
>
>
> Error: unexpected '=' in " lines(xx,predict(power,list(log(ArKm00,10)="
>
> I would really appreciate any help sorting this out!
>
> Many thanks
>
> Mark
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list