I have some data of longitudes and latitudes. My third variable is the penetration of the electric Vehicle in an municipality. Hence, I have sparse datas and I do not know the mapping from f(long,lat) -> MS_Year. I have the following datas
long lat MS_Year
<dbl> <dbl> <dbl>
1 -66.0436169857389 50.3417726256247 0.0122
2 -66.1704063635085 48.168838536499 0.0115
3 -67.1376617834163 48.9202603958534 0.0136
4 -67.474931686395 48.8025438021711 0.0108
5 -67.5756670981796 48.5194066352801 0.0111
6 -67.6273066949175 48.429540936994 0.0167
I have been able to do the 3D scatter plot without any problems.
scatterplot3d(Plot_Me_Tot_2019_grouped)
[enter image description here][1]
However, I've spent the whole day trying to understand how to do a surface. To my understanding, it is particularly hard, because I need to use a nonparametric estimator to show how complex the topology is. (The idea is to justify a nonparametric regression, which I've just learned about and never used; it might explain my total struggle).
Hence, I need to create a polynomial function f(long,lat) that has output MS_Year.
I Tried to applied it as follow :
library(predict3d)
library(rgl)
fit5=lm(MS_Year ~polym(long, lat,degree=5, raw=T),data=Plot_Me_Tot_2019_grouped)
predict3d(fit5,radius=0.05)
I did that, caused It combines this [polynomial regression][2], to this [3D plotting][3]. It's a total failure.
Did someone ever faced similar issues ?
I feel my problem is to create the linked function AKA the f(long,lat) and then with this, use expand.grid(long,lang) to create a surface and plot it.
One should understand that I do not posses a good understanding of the translation from the DF to the matrix format required for the 3D surface.
Thanks a lot for your time [1]: https://i.stack.imgur.com/6ceJj.png [2]: Polynomial regression with two variables with R [3]: https://cran.r-project.org/web/packages/predict3d/vignettes/predict3d.html