Search code examples
rpredictionforecasting

Predict the next values based on the given data in R


I have a vector which represents violations in each year.How to predict the violations in the next years in R.

year <- c(190519, 223721, 235321, 101934)

Please help me out


Solution

  • To illustrate the comments made by akash87 and Dominic Comtols that it would be futile to predict with little information, here's a linear model method and visualisation with ggplot:

    year<-c(190519 ,223721, 235321, 101934)
    df <- data.frame(year=1:4, crime= year)
    library(ggplot2)
    
    ggplot(df, aes(x=year, y=crime)) + 
           geom_point() + 
           geom_smooth(method="lm", fullrange=T) + 
           xlim(1,6)
    

    enter image description here

    As seen from the plot, the predicted value by extrapolating the linear model in Year 6 can be anyway within the gray area, i.e between -339737 and 537576. You're better off just guess...