Difference between revisions of "PowerExtrapolation.R"

From Organic Design wiki
 
m
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
# {{R}}
 
library(chron)
 
library(chron)
  
 
dset <- scan(what="")
 
dset <- scan(what="")
 
11/1/00 10.70 60
 
11/1/00 10.70 60
5/1/05 11.81 33.26
+
5/1/02 11.81 33.26
 
1/1/02 12.36 34.8
 
1/1/02 12.36 34.8
 
4/1/02 11.84 33.67
 
4/1/02 11.84 33.67
Line 21: Line 22:
 
dset <- as.data.frame(t(dset))
 
dset <- as.data.frame(t(dset))
 
colnames(dset) <- c("Date", "kwh", "dailyCharge")
 
colnames(dset) <- c("Date", "kwh", "dailyCharge")
 +
 +
dset$Date <- dates(levels(dset$Date)[unclass(dset$Date)])
 +
 +
 +
plot(dset$Date, as.numeric(as.vector(dset$kwh)))
 +
 +
 +
y <- as.numeric(as.vector(dset$kwh))
 +
x <- (dset$Date - dates("11/01/00")) / 365.25
 +
 +
# Plot in years
 +
plot(x,y)
 +
lowessObj <- lowess(y~x)
 +
lines(lowessObj)
 +
 +
# Percent increase in electricity price in five years
 +
# Percent increase in electricity price in five years
 +
increase <- diff(range(lowessObj$y)) / min(lowessObj$y)
 +
increase
 +
 +
# Per annum increase (approximate, trend is linear not exponential compounding)
 +
(1+increase) ^ (1/diff(range(lowessObj$x))) - 1

Latest revision as of 00:44, 6 June 2007

Code snipits and programs written in R, S or S-PLUS library(chron)

dset <- scan(what="") 11/1/00 10.70 60 5/1/02 11.81 33.26 1/1/02 12.36 34.8 4/1/02 11.84 33.67 10/1/02 11.82 33.64 3/1/03 11.82 33.33 10/1/03 13.84 33.33 10/1/04 13.77 33.33 11/1/04 15.26 33.33 12/1/04 14.07 59.59 4/1/05 14.528 60.55 10/1/05 15.7 64.68 3/1/06 16.4 66.02 6/1/06 14.78 33.33 ""

dim(dset) <- c(3, length(dset)/3) dset <- as.data.frame(t(dset)) colnames(dset) <- c("Date", "kwh", "dailyCharge")

dset$Date <- dates(levels(dset$Date)[unclass(dset$Date)])


plot(dset$Date, as.numeric(as.vector(dset$kwh)))


y <- as.numeric(as.vector(dset$kwh)) x <- (dset$Date - dates("11/01/00")) / 365.25

  1. Plot in years

plot(x,y) lowessObj <- lowess(y~x) lines(lowessObj)

  1. Percent increase in electricity price in five years
  2. Percent increase in electricity price in five years

increase <- diff(range(lowessObj$y)) / min(lowessObj$y) increase

  1. Per annum increase (approximate, trend is linear not exponential compounding)

(1+increase) ^ (1/diff(range(lowessObj$x))) - 1