-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinModTSfit.R
More file actions
161 lines (140 loc) · 4.99 KB
/
Copy pathlinModTSfit.R
File metadata and controls
161 lines (140 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
source("treatmentClasses.R")
source("treatmentAnaerobicDigestion.R")
source("treatmentLandApplication.R")
source("treatmentcompost.R")
source("treatmentLandfill.R")
source("parseGlobalFactors.R")
source("baselines.R")
# o is in the env when you source baselines.R# ADLM <- lm(I(unlist(o$AD[1])) ~ I(o$f1$Bo/500) + I(o$f1$TS) +
# I(o$f1$VS) + I(o$f1$TKN/20000)))
TKN<-o$f1$TKN
TDN<-o$f1$TDN
Lo<-o$f1$Lo
TVS<-o$f1$TVS
InitialC<-o$f1$InitialC
fdeg <- o$f1$fdeg
rdeg <- o$f1$rdeg
npert <- o$f1$Nperton
Bo <- o$f1$Bo
TS <- o$f1$TS
percentProteinTS <- o$f1$percentProteinTS
percentLipidTS <- o$f1$percentLipidTS
percentCarboTS <- o$f1$percentCarboTS
# scaling is done by dividing the columns of x by the root mean square of the vector
# this is the default scaling algorithm in the r scale function
scaledTKN <- (TKN - min(TKN))/(max(TKN)-min(TKN))
scaledLo <- (Lo - min(Lo))/(max(Lo)-min(Lo))
scaledTS <- (TS - min(TS))/(max(TS)-min(TS))
scalednpert <- (npert - min(npert))/(max(npert)-min(npert))
scaledTDN <- (TDN - min(TDN))/(max(TDN)-min(TDN))
scaledTVS <- (TVS - min(TVS))/(max(TVS)-min(TVS))
scaledInitialC <- (InitialC - min(InitialC))/(max(InitialC)-min(InitialC))
scaledfdeg <- (fdeg - min(fdeg))/(max(fdeg)-min(fdeg))
# scaledTKN<-scale(o$f1$TKN, center = FALSE)
# scaledTDN<-scale(o$f1$TDN, center = FALSE)
# scaledLo<-scale(o$f1$Lo, center = FALSE)
# scaledTVS<-scale(o$f1$TVS, center = FALSE)
# scaledInitialC<-scale(o$f1$InitialC, center = FALSE)
# scaledfdeg <- scale(o$f1$fdeg, center = FALSE)
# scaledrdeg <- scale(o$f1$rdeg, center = FALSE)
# scalednpert <- scale(o$f1$Nperton, center = FALSE)
# scaledTS <- scale(o$f1$TS, center = FALSE)
par(mfrow=c(2,2),oma = c(0, 0, 2, 0))
#AFLM <- lm(unlist(o$AF[1]) ~ TS : TDN) # perfect fit!
AFLM <- lm(unlist(o$AF[1]) ~ TS )
print(summary(AFLM))
#plot(AFLM)
coef(AFLM)
TSTDN <- TS * TDN
scaledTS_TDN <- (TSTDN - min(TSTDN))/(max(TSTDN) - min(TSTDN))
AFLMS <- lm(unlist(o$AF[1]) ~ scaledTS_TDN) # perfect fit!
#summary(AFLMS)
#plot(AFLMS)
coef(AFLMS)
# AFLM <- lm(unlist(o$AF[1]) ~ TS )
# summary(AFLM)
# #plot(AFLM)
# coef(AFLM)
# # plot(fitted(AFLM),unlist(o$AF[1]),xlab="fit",ylab="Animal Feed Emissions")
# # lines(c(-600,2500),c(-600,2500))
#
# AFLM <- lm(unlist(o$AF[1]) ~ TS:percentProteinTS +
# TS:percentLipidTS + TS:percentCarboTS )
# summary(AFLM)
# #plot(AFLM)
# coef(AFLM)
# # plot(fitted(AFLM),unlist(o$AF[1]),xlab="fit",ylab="Animal Feed Emissions")
# # lines(c(-600,2500),c(-600,2500))
# Good Fit
# ADfLM <- lm(unlist(o$ADf[1]) ~ Lo + TVS + InitialC:rdeg)
# Perfect Fit
#ADfLM <- lm(unlist(o$ADf[1]) ~ Lo + TVS + InitialC:fdeg + TKN + InitialC)
ADfLM <- lm(unlist(o$ADf[1]) ~ TS)
print(summary(ADfLM))
#plot(ADfLM)
coef(ADfLM)
#plot(fitted(ADfLM),unlist(o$ADf[1]),xlab="fit",ylab="AD Emissions")
#lines(c(-600,2500),c(-600,2500))
# ADfLMS <- lm(unlist(o$ADf[1]) ~ scaledLo + scaledTVS)
# summary(ADfLMS)
# #plot(ADfLMS)
# coef(ADfLMS)
# plot(fitted(ADfLMS),unlist(o$ADf[1]),xlab="fit",ylab="AD emission")
# lines(c(-600,2500),c(-600,2500))
ADfLMS <- lm(unlist(o$ADf[1]) ~ scaledLo + scaledTVS + + scaledTKN + scaledInitialC : scaledfdeg + scaledInitialC)
#ADfLMS <- lm(unlist(o$ADf[1]) ~ scaledLo + scaledTVS)
summary(ADfLMS)
#plot(ADfLMS)
coef(ADfLMS)
# Perfect Fit
#CMbLM <- lm(unlist(o$CMb[1]) ~ npert + InitialC )
CMbLM <- lm(unlist(o$CMb[1]) ~ TS )
print(summary(CMbLM))
#plot(CMbLM)
coef(CMbLM)
#plot(fitted(CMbLM),xlab="Feedstock",ylab="Compost Emissions")
#points(o$CMb[1], cex=2)
CMbLMS <- lm(unlist(o$CMb[1]) ~ scalednpert + scaledInitialC)
#summary(CMbLMS)
#plot(CMbLMS)
coef(CMbLMS)
y<-unlist(o$LF[1])
names(y) <- o$f1$type
# Good Fit
#LFLM <- lm(y ~ Lo + InitialC)
# perfect fit
#LFLM <- lm(y ~ Lo + InitialC:rdeg)
LFLM <- lm(y ~ TS)
print("landfill")
print(summary(LFLM))
#plot(LFLM, las = 1)
#plot(fitted(LFLM),unlist(o$LF[1]),xlab="fit",ylab="LF emission")
#lines(c(-600,3500),c(-600,3500))
coef(LFLM)
#
# LFLM <- lm(y ~ TS + InitialC)#:rdeg) # perfect fit!
# summary(LFLM)
# #plot(LFLM, las = 1)
# coef(LFLM)
LFLMS <- lm(unlist(o$LF[1]) ~ scaledLo + scaledInitialC)# : scaledrdeg)
summary(LFLMS)
#plot(LFLMS)
coef(LFLMS)
# plot(fitted(AFLM),xlab="Feedstock",ylab="Animal Feed Emissions")
# points(o$AF[1], cex=2)
# plot(fitted(ADfLM),xlab="Feedstock",ylab="Anaerobic Digestion Emissions")
# points(o$ADf[1], cex=2)
# plot(fitted(CMbLM),xlab="Feedstock",ylab="Compost Emissions")
# points(o$CMb[1], cex=2)
# plot(fitted(LFLM),xlab="Feedstock",ylab="Landfill Emissions")
# points(y, cex=2)
# mtext("Linear Models fit vs. actual", outer = TRUE, cex = 1.5)
plot(fitted(AFLM),unlist(o$AF[1]),xlab="fit",ylab="Animal Feed Emissions")
lines(c(-600,2500),c(-600,2500))
plot(fitted(ADfLM),unlist(o$ADf[1]),xlab="fit",ylab="Anaerobic Digestion Emissions")
lines(c(-600,2500),c(-600,2500))
plot(fitted(CMbLM),unlist(o$CMb[1]),xlab="fit",ylab="Compost Emissions")
lines(c(-600,2500),c(-600,2500))
plot(fitted(LFLM),unlist(y),xlab="fit",ylab="Landfill Emissions")
lines(c(-600,3500),c(-600,3500))
mtext("Linear Models fit vs. actual (JUST TS)", outer = TRUE, cex = 1.5)