I am trying to create predictions from my model, but i wish to keep the Country_Name in the predictions if possible. Is there any way this can be done as i'm having no lucking using the standard predict() function
My model is;
mod = gam(gdp_per_capita ~ s(fisheries_production_pc, k = 10, bs = 'cs') s(food_yield_pc, k = 10, bs = 'cs')
s(freshwaster_production_pc, k = 5, bs = 'cs') s(co2, k = 5, bs = 'cs') Country_Name,
data = economy_df,
family = gaussian(link = "log"))
data snipet;
economy_df
Country_Name year gdp_per_capita Agriculture_GDP_per fisheries_production_pc food_yield_pc freshwaster_production_pc co2
Albania 2018 5287.6637 18.4294792 0.0052701739 1.688718e-03 3.342199e-07 1.782739
Albania 2019 5396.2159 18.3893474 0.0053295312 1.765194e-03 3.342199e-07 1.692248
Albania 2020 5332.1605 19.2644408 0.0059591472 1.835616e-03 3.342199e-07 3.926145
Algeria 2018 4142.0186 11.8742008 0.0028456292 4.622480e-05 2.321186e-07 3.920109
Algeria 2019 3989.6683 12.3362121 0.0024478768 4.105168e-05 2.321186e-07 3.977650
Algeria 2020 3306.8582 14.1347926 0.0019817330 3.467192e-05 2.321186e-07 2.448906
Bosnia 2018 6070.3530 5.8854355 0.0011864874 1.651028e-03 1.206103e-07 6.799183
Bosnia 2019 6119.7624 5.6030922 0.0012912459 1.622146e-03 1.206103e-07 6.382918
Bosnia 2020 6082.3667 6.0844855 0.0012438373 1.844267e-03 1.206103e-07 4.962175
Croatia 2018 15227.5601 2.9570919 0.0220747984 1.725996e-03 1.646345e-07 4.019235
Croatia 2019 15311.7669 2.8687641 0.0209151509 1.760604e-03 1.646345e-07 4.063708
Croatia 2020 14132.4866 3.2165075 0.0230609534 1.727508e-03 1.646345e-07 8.057848
Cyprus 2018 29334.1113 1.7335399 0.0074306923 8.853390e-04 1.740575e-07 6.054175
Cyprus 2019 29206.0762 1.8086052 0.0079922641 2.216217e-03 1.740575e-07 5.998795
Cyprus 2020 27681.5664 1.9308417 0.0071299388 1.961717e-03 1.740575e-07 5.614297
Egypt 2018 2537.1252 11.2250002 0.0199902966 6.887169e-05 7.874128e-07 2.518806
Egypt 2019 3019.0923 11.0489759 0.0203110909 6.022130e-05 7.874128e-07 2.484060
Egypt 2020 3569.2068 11.5676091 0.0196471464 6.046745e-05 7.874128e-07 5.295201
What I'm looking for would look something like this i imagine:
Country_Name prediction
Albania <value>
Albania <value>
Albania <value>
CodePudding user response:
To check the order of values you can perform a correlation between observed versus predicted values:
cor(economy_df$gdp_per_capita,preds[["fit"]])
Then make new df with your desired columns:
mypred<-data.frame(Country_Name =
economy_df$Country_Name
,prediction=preds[["fit"]])
head(mypred)
Country_Name prediction
1 Albania 5259.356
2 Albania 5382.758
3 Albania 5373.350
4 Algeria 4099.978
5 Algeria 3951.231
6 Algeria 3402.162