How to calculate uncertainty in the sum of the predictions for log model

Viewed 15

I want to apply similar concept as was discussed here, but for model with log-transformed variables.

my data:

df=structure(list(bio = c(0.0979, 0.0967, 0.02465, 0.04435, 0.11725, 
0.1627, 0.04, 0.587, 0.3526, 0.7569, 0.7605, 0.4741, 1.08133333333333, 
0.7867, 1.42275, 0.9524, 0.2597, 0.0883, 0.2449, 0.03145, 0.03325, 
0.0767, 0.4677, 0.0584, 0.1086, 0.2975, 0.3741, 0.33245, 0.5031, 
0.1763, 0.069, 0.0816, 0.169, 0.786, 0.425, 1.3413, 0.5996, 0.3097, 
0.0031, 0.022, 0.4405, 0.5393, 1.3246, 0.8198), npp = c(218.82107035319, 
121.504152933757, 150.33682929145, 218.550893147786, 276.517130533854, 
349.569854736328, 198.919808281793, 217.842965443929, 311.313401963976, 
357.415242513021, 323.259494357639, 273.382185194227, 324.124850802951, 
400.985666910807, 445.559258355035, 268.33075120714, 165.860109117296, 
212.145429823134, 173.391438802083, 174.656700981988, 117.246879577637, 
231.400204128689, 172.146889580621, 162.356897989909, 308.175516764323, 
280.752919514974, 314.384904649523, 309.407111273872, 292.705355326335, 
197.660367329915, 297.175706651476, 358.328002929688, 206.897630479601, 
320.320393880208, 207.519053141276, 263.267913818359, 358.764539082845, 
181.183760325114, 154.821061876085, 205.742538452148, 350.833702087402, 
326.256442599826, 385.434377034505, 658.054239908854)), row.names = c(NA, 
-44L), class = c("tbl_df", "tbl", "data.frame"))

newdf=structure(list(npp = c(209.96727945347, 124.96744257609, 130.669062343644, 
87.5727598667145, 70.7044902907477, 84.3105547428131, 156.320644348387, 
196.061843472435, 241.122909634202, 224.017583710807), pred_bio = c(`1` = 0.138277771264287, 
`2` = 0.040836228098044, `3` = 0.0453512804649462, `4` = 0.0177033648027766, 
`5` = 0.010706271639848, `6` = 0.0161920617114052, `7` = 0.0691137488725324, 
`8` = 0.117707340206985, `9` = 0.19142087859615, `10` = 0.161017983879625
), bio = c(`1` = 0.138277771264287, `2` = 0.040836228098044, 
`3` = 0.0453512804649462, `4` = 0.0177033648027766, `5` = 0.010706271639848, 
`6` = 0.0161920617114052, `7` = 0.0691137488725324, `8` = 0.117707340206985, 
`9` = 0.19142087859615, `10` = 0.161017983879625)), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))

I have teh following model:

model=lm(log(bio)~ log(npp), data=df)

i make predictions:

newdf$bio= exp(predict(model,newdf))

sum of the predictions:

sum(newdf$bio)

then i want to calculate the standard error for the sum of predictions ( not logged):

v <-colSums(exp(model.matrix(formula(model), newdf)))
se <- sqrt(v %*% exp(vcov(model)) %*% v)
se

Am I correct in exponentiating model.matrix and vcov matrices? OR I should leave it as it is:

v <-colSums(model.matrix(formula(model), newdf))

se <- sqrt(v %*% vcov(model) %*% v)
se
1 Answers

I assumed, based on obtained values, that SE should not be exponentiated:

v <-colSums(model.matrix(formula(model), newdf))

se <- sqrt(v %*% vcov(model) %*% v)
se
Related