Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 821901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:43:06+00:00 2026-05-15T02:43:06+00:00

I’m using R. I have 25 variables over 15 time points, with 3 or

  • 0

I’m using R. I have 25 variables over 15 time points, with 3 or more replicates per variable per time point. I’ve melted this into a data.frame, which I can plot happily using (amongst other things) ggplot’s facet_wrap() command. My melted data frame is called lis; here’s its head and tail, so you get an idea of the data:

> head(lis)
  time variable    value
1   10     SELL 8.170468
2   10     SELL 8.215892
3   10     SELL 8.214246
4   15     SELL 8.910654
5   15     SELL 7.928537
6   15     SELL 8.777784
> tail(lis)
    time variable    value
145    1     GAS5 10.92248
146    1     GAS5 11.37983
147    1     GAS5 10.95310
148    1     GAS5 11.60476
149    1     GAS5 11.69092
150    1     GAS5 11.70777

I can get a beautiful plot of all the time series, along with a fitted spline and 95% confidence intervals using the following ggplot2 commands:

p <- ggplot(lis, aes(x=time, y=value)) + facet_wrap(~variable)
p <- p + geom_point() + stat_smooth(method = "lm", formula = y ~ ns(x,3))

The trouble is that the smoother is not to my liking – the 95% confidence intervals are way off. I would like to use Gaussian Processes (GP) to get a better regression and estimate of covariance for my time series.

I can fit a GP using something like

library(tgp) 
out <- bgp(X, Y, XX = seq(0, 200, length = 100))

which takes time X, observations Y and makes predictions at each point in XX. The object out contains a bunch of things about those predictions, including a covariance matrix I can use in place of the 95% confidence interval I get (I think?) from ns().

The trouble is I’m not how to wrap this function to make it interface with ggplot2::stat_smooth(). Any ideas or pointers as to how to proceed would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:43:07+00:00Added an answer on May 15, 2026 at 2:43 am

    Stat_smooth has y, ymin, and ymax aesthetics that you can use with a custom smoother, as documented here: http://had.co.nz/ggplot2/stat_smooth.html. You create a data frame with the predictions and CI from your custom smoother and use that directly in stat_smooth (specifying a new data argument). You might be able to use stat_smooth(method="tgp::bgp",XX=seq(0,200,length=100)) but I haven’t tried it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.