[R] Smoothing by group - Panel data - exponential/loess

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Oct 7 22:42:56 CEST 2018


1. This doesn't make much sense:

smoothdf <- data.frame(
  x = 1:n,
  y = as.vector(smooth(dat$g)),
  method = "smooth()"
)

What do you think the "method" invocation does (data.frame has no "method"
argument)?

2. Show us what you have tried -- it depends on what graphics system you
use. In lattice and ggplot2, for example, it's pretty basic. In base
graphics, see ?scatter.smooth, for example -- it would have to be called
for each separate group, of course. See e.g. ?tapply and friends for
processig by separate groups. I'd also suggest that you spend time with a
basic R tutorial or two, where this sort of thing is usually covered.

3. Numerous packages also do this: searching on "plot smooth curves by
groups" on rseek.org brought up lots of stuff.

Cheers,
Bert





Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Oct 7, 2018 at 10:59 AM Miluji Sb <milujisb using gmail.com> wrote:

> Dear all,
>
> I have panel data for a series (g) for three time periods. The variable is
> likely autocorrelated. I would like to generate a new variable using
> exponential/loess smoothing by group (gid).
>
> For time series, I could have done something like this;
>
> smoothdf <- data.frame(
>   x = 1:n,
>   y = as.vector(smooth(dat$g)),
>   method = "smooth()"
> )
>
> But confused about the panel data setting. Apologies if this a stat
> question along with an R query. Any help will be greatly appreciated.
>
> ### data
> structure(list(gid = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L,
> 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L,
> 9L), year = c(2030L, 2050L, 2100L, 2030L, 2050L, 2100L, 2030L,
> 2050L, 2100L, 2030L, 2050L, 2100L, 2030L, 2050L, 2100L, 2030L,
> 2050L, 2100L, 2030L, 2050L, 2100L, 2030L, 2050L, 2100L, 2030L,
> 2050L, 2100L), g = c(9.24e-05, 0.0001133, 6.3e-05, 7.72e-10,
> 1.41e-09, 4.68e-09, 0.0001736, 0.0002286, 0.0001541, 1.87e-15,
> 3.76e-15, 8.52e-15, 0.0001822, 0.0002391, 0.0001348, 3.69e-06,
> 8.11e-06, 8.63e-06, 3.41e-06, 7.32e-06, 7.18e-06, 8.47e-07, 1.83e-06,
> 1.84e-06, 1.13e-06, 2.37e-06, 2.15e-06)), class = "data.frame", row.names =
> c(NA,
> -27L))
>
>
> Sincerely,
>
> Milu
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org 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]]




More information about the R-help mailing list