'how to make the Expected value curve for a longitudinal data in r

I have a longitudinal data where I would like to make the expected value curve. In the x-axis I have time and in the y-axis I have a continuous variable.



Solution 1:[1]

Without data it is hard to reproduce your problem first I generated some random data:

df <- data.frame(Age = sample(1:50),
                 variable = runif(50, 0, 1))

I am not sure if this is what you want, but you can use geom_smooth to create an expected value curve using this code:

library(tidyverse)
df %>%
  ggplot(aes(x = Age, y = variable)) +
  geom_point() +
  geom_smooth()

Output:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quinten