Re: Warning Message !!!! stat_smooth( method= "lm" or "gam" )

769 views
Skip to first unread message

Ista Zahn

unread,
Jan 29, 2013, 7:16:14 PM1/29/13
to nserdar, ggplot2


On Jan 29, 2013 6:43 PM, "nserdar" <snes...@gmail.com> wrote:
>
> Lenght of Data Set= 522 
>
> # Works Properly
>
> ggplot(tdata,aes(x=X2,y=X1))+geom_point()+stat_smooth(method=lm)
>
>
> # warning message
> ggplot(tdata,aes(x=X2,y=X1))+geom_point()+stat_smooth(method=lm,formula=X1~X2,se=F)

This should be formula = y~x
>
> Error in data.frame(x = xseq, y = as.vector(pred)) : 
>   arguments imply differing number of rows: 80, 522
> In addition: Warning message:
> 'newdata' had 80 rows but variable(s) found have 522 rows
>
> # How to stat_smooth for X1~ X2+X2^2+X2^3  ??? I use "ns" in formula part, than give same warnings message like above !!

I don't think you can
>
> ##################################################
>
> gam ()  function smooth 
>
> #Warning message
>
> Error in data.frame(x = xseq, y = model$family$linkinv(as.vector(pred$fit)),  : 
>   arguments imply differing number of rows: 80, 522
> In addition: Warning messages:
> 1: In predict.gam(model, newdata = data.frame(x = xseq), se = se, type = "link") :
>   not all required variables have been supplied in  newdata!
>
> 2: 'newdata' had 80 rows but variable(s) found have 522 rows 
>
> ##################################################
>
> Please let me know how to solve these warnings 
>
> Regards,
> Serdar
>
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
>  
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>  
> ---
> You received this message because you are subscribed to the Google Groups "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

Dennis Murphy

unread,
Jan 29, 2013, 10:04:21 PM1/29/13
to nserdar, Ista Zahn, ggplot2
Hi:

Ista's remarks are dead on in terms of the formula notation, but as
long as the fitting function is in terms of one variable, one should
be able to plot it in geom_smooth(). If it is a function of more than
one explanatory variable, it cannot be plotted in ggplot2 as it
becomes a function of more than two variables (which I think is what
Ista was getting at).

Since the OP evidently wants to fit several such models to his data,
the geom can be called several times with a different model formula
for each call. Here's a small toy example:

DF <- data.frame(x = seq(10), y = 2 + 0.5 * seq(10) + rnorm(10, sd = 0.6))
# library(ggplot2)
ggplot(DF, aes(x = x, y = y)) +
geom_smooth(aes(color = "linear"), method = "lm", size = 1, se = FALSE) +
geom_smooth(aes(color = "quadratic"), method = "lm",
formula = y ~ poly(x, 2), size = 1, se = FALSE) +
geom_smooth(aes(color = "cubic"), method = "lm", formula = y ~ poly(x, 3),
size = 1, se = FALSE) +
scale_color_manual("model", values = c("blue", "brown", "orange"))

Dennis

Serdar Neslihanoglu

unread,
Jan 30, 2013, 7:07:33 AM1/30/13
to ANTONIOSPARS, ggplot2
Thanks for your great example !!!!

But problem is appeared related to legend. 

That is, Order of legend output

Cubic
Linear
Quadratic 

How to modify this order like that 

Linear
Quadratic
Cubic 

Please let me know how to do that with new order !!!!

Regards,
Serdar

On Wed, Jan 30, 2013 at 9:11 AM, ANTONIOSPARS <antoni...@gmail.com> wrote:
has anyone used the chain ladder package



Reply all
Reply to author
Forward
0 new messages