0

I have two datasets. The first one shows information about multiple weather phenomena in Brazil measured by weather stations in the country. I also have information regarding the latitude and longitude of these stations, and the weather data is provided by year.

id_estacao  ano precipitacao_total pressao_atm_max pressao_atm_min
1       A001 2016         0.12988728        888.0399        887.5521
2       A002 2016         0.14282787        932.8559        932.3215
3       A003 2016         0.12486339        930.6114        930.0861
4       A009 2016         0.07696277        979.3086        978.7480
5       A010 2016         0.11548640        980.2251        979.6578
6       A011 2016         0.13886103        958.5196        957.9678
  radiacao_global temperatura_max temperatura_min umidade_rel_max
1        1508.024        22.77794        21.34106        65.52186
2        1419.644        24.90139        23.40798        66.28074
3        1460.937        24.00484        22.46128        68.25395
4        1440.643        29.22710        27.79419        61.87001
5        1540.398        27.52555        25.87737        63.64414
6        1471.004        24.95090        23.36305        66.69974
  umidade_rel_min vento_velocidade id_municipio   estacao  latitude
1        59.04111        2.3430377      5300108  Brasilia -15.78944
2        59.56990        1.2416667      5208707   Goiania -16.64284
3        59.71499        1.6017190      5213806 Morrinhos -17.74507
4        55.21366        1.5202973      1721000    Palmas -10.19074
5        57.01889        0.9295148      1716208    Parana -12.61500
6        60.26358        1.7454093      5220405 Sao Simao -18.96914
  longitude
1 -47.92583
2 -49.22022
3 -49.10170
4 -48.30181
5 -47.87194
6 -50.63345

Moreover, I have information about the location of the Brazilian municipalities (cities).

  id_municipio latitude longitude
1      1100015   -11.92    -61.99
2      1100023    -9.91    -63.04
3      1100031   -13.49    -60.54
4      1100049   -11.43    -61.44
5      1100056   -13.18    -60.81
6      1100064   -13.11    -60.54

I want to use interpolation to predict the weather phenomena in these cities using the information provided in the first dataset. I have been working with the package "fields", which uses this function:

# Kriging of the rainfall data by station
      fit = Krig(x,precip[,d])
      
      # Predict the value on the unit
      pred<-predict(fit,Y)

It basically makes a loop with d-days (in this case, years). precip[,d] is the precipitation variable (in this case, all the weather variables) on day d, and x is the latitude and longitude of the station. This should provide a fit which is the output of krig and Y (the latitude and longitude of the municipalities).

However, I have been struggling to make this function fit my data. I would like to know if someone could help me.

Mateus Maciel
  • 151
  • 1
  • 1
  • 10
  • This [transitioning from raster sp to sf terra stars, pg 5](https://psfaculty.plantsciences.ucdavis.edu/plant/AdditionalTopics_Transition.pdf) may be worth a look. Will also help if you `dput(head(my_data1))` and put `structure(...)` above as data for both. – Chris Jan 07 '23 at 15:32

0 Answers0