0

I have data of womens mile world record progression and have fit the model

women$Time <- c(277.00, 276.80, 275.30, 269.50, 263.80, 262.10, 261.70, 260.89, 258.08, 257.44, 256.71, 255.61, 252.56, 252.33)
women$Year <- c(1967, 1969, 1971, 1973, 1977, 1979, 1980, 1981, 1982, 1982, 1985, 1989, 1996, 2019))

wmod<- drm(women, Time ~ Year-1967, fct = EXD.3()

I have plot the model using ggplot

wpred <- predict(wmod, interval='conf', level=0.95) #getting confidence interval 
y<- cbind(women, wpred) #combining with original dataframe

ggplot(data=y, aes(x=Year, y=Time))+geom_point()+
  geom_line(aes(y=fitted(w2)))+theme_minimal()+
  geom_ribbon(aes(ymin= Lower, ymax=Upper), alpha=0.3, fill="pink")+
  ggtitle('Womens Fitted Model')+theme(plot.title = element_text(hjust = 0.5, face="bold"))

and it looks great, I can see the confidence interval, the model line and the points. When I extend x axis by adding scale_x_continuous(limits=c(1967, 2100)) it re-adjusts the axis but doesn't include the model or confidence interval. How do I also readjust the model to extend further?

I have tried readjusting scale limits but the plot of the model doesn't extend with it.

L B
  • 11
  • 2

1 Answers1

0

The line didn't plot further because the plot didn't know what values to plot, i.e. the prediction doesn't go beyond 2019, so it can't plot out to 2100.

You need to provide the code for a reproducible, minimal example in the future. You don't show all of women and you don't list the libraries you use. How to make a great R reproducible example

# You start off adding columns to a data frame called women.
# Where did that come from? I create women2 for this example.
women2 <- data.frame(Time=c(277.00, 276.80, 275.30, 269.50, 263.80, 262.10, 261.70, 260.89, 258.08, 257.44, 256.71, 255.61, 252.56, 252.33), Year = c(1967, 1969, 1971, 1973, 1977, 1979, 1980, 1981, 1982, 1982, 1985, 1989, 1996, 2019))
women2$year2 <- women2$Year - 1967

# I use lm() because you don't provide what packages you are using
# and so I don't know what drc is.
wmod<- lm(Time ~ year2, data=women2)

# This prediction is only for the Years that you provide at start.
wpred <- predict(wmod, interval='conf', level=0.95) #getting confidence interval 
y<- cbind(women2, wpred) #combining with original dataframe

# Has no values past 2019, so it doesn't know what to plot
y
     Time Year year2      fit      lwr      upr
1  277.00 1967     0 270.8327 266.0728 275.5926
2  276.80 1969     2 269.7776 265.3759 274.1793
3  275.30 1971     4 268.7226 264.6535 272.7916
4  269.50 1973     6 267.6675 263.8987 271.4363
5  263.80 1977    10 265.5573 262.2575 268.8572
6  262.10 1979    12 264.5023 261.3514 267.6531
7  261.70 1980    13 263.9747 260.8729 267.0765
8  260.89 1981    14 263.4472 260.3763 266.5181
9  258.08 1982    15 262.9196 259.8609 265.9784
10 257.44 1982    15 262.9196 259.8609 265.9784
11 256.71 1985    18 261.3370 258.2020 264.4721
12 255.61 1989    22 259.2269 255.7509 262.7029
13 252.56 1996    29 255.5341 251.0071 260.0611
14 252.33 2019    52 243.4008 234.0116 252.7900

# Make up a data frame with future Years. Goes to 2100 since that was 
# in the body of your question. I left the values for Time blank (NA).
# I only do a few years for this example.
futwom <- data.frame(Time=rep(NA,3), Year=c(2020,2040,2100))
futwom$year2 <- futwom$Year - 1967

# Make a prediction with the new data frame as "newdata")
wpred2 <- predict(wmod, interval='conf', level=0.95, newdata=futwom) 
y2
      Time Year year2      fit      lwr      upr
1       NA 2020    53 242.8732 233.2560 252.4905
2       NA 2040    73 232.3225 218.0558 246.5891
3       NA 2100   133 200.6702 172.1200 229.2205

# Star to combine stuff for plotting
y2 <- cbind(futwom, wpred2)

# Now I provide some kind of value to Time now. THIS METHOD IS ONLY for 
# illustrative purposes. You should see if there is a more rigorous method.
y2$Time <- y2$fit + jitter(2.5)

# Combine stuff for plotting
y3 <- rbind(y, y2)

ggplot(data=y3, aes(x=Year, y=Time))+geom_point()+
  geom_line(aes(y=fit))+theme_minimal()+
  geom_ribbon(aes(ymin= lwr, ymax=upr), alpha=0.3, fill="pink")+
  ggtitle('Womens Fitted Model')+theme(plot.title = element_text(hjust = 0.5, face="bold")) + scale_x_continuous(limits=c(1967, 2100))

Looks like this:

scatter plot with regression line. Year on X axis, Running time on Y axis

John Polo
  • 547
  • 1
  • 8
  • 25
  • Thank you for this. drm a package for dose response modelling. It works if you do not put in time in the new dataframe. Again thanks!!! – L B Mar 14 '23 at 05:52