How do I draw the line for change-point detection using/after doing a Pettitt test.

This is my plot

This is my code so far for the plot
#From 2004 to 2019, Canada, Buildings--#
x = (2004:2019)
y = integer(19)
y = as.double(y)
len = dim(Buildings)[1]
rng = (1:len)
for (i in rng) {
idx = strtoi(Buildings[i,2]) - 2000
y[idx] = y[idx] + as.double(Buildings[i,77])
}
y=y[04:19]

matplot(x, y, type="b", lty=4, pch = 18, col="blue",xlab="Year",
ylab="Total Emission",main = "Building Sector 2004-2019", lwd = '3')

pettittTest <- trend::pettitt.test(x = Buildings[['TotalEmi']])
print(pettittTest)

print(Buildings[['Year']][pettittTest$estimate])

Thanks in advance

We need a reproducible example (reprex)

Any particular reason for using matplot?

When I try this

x = (2004:2019)

y = integer(19)

y = as.double(y)

y=y[04:19]

matplot(x, y, type="b", lty=4, pch = 18, col="blue",xlab="Year",
        
        ylab="Total Emission",main = "Building Sector 2004-2019", lwd = '3')

all I get is a flat line with y == 0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.