Problems with kriging function in R - r

I have a dataframe named as kef, consisted of 512 rows, and the fields x, y (referring to coordinates) and v (refering to a certain numeric value for each cell).
I also have a map layer named as grecia.map, loaded in R through the readOGR command consisted of a polygon which represents a certain area.
While running the following command:
kriged <- kriging(kef$x, kef$y, kef$v, polygons = grecia.map, pixels=30000)
I receive the following error messages:
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
0 (non-NA) cases
In addition: Warning messages:
1: In max(x) : no non-missing arguments to max; returning -Inf
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(y) : no non-missing arguments to max; returning -Inf
4: In min(y) : no non-missing arguments to min; returning Inf

Well, I managed to correct the issue. The problem had to do with the data. the coordinates along with the sample values were messed and apparently there was not any spatial logic with the data.
After importing a correct dataset the function worked properly so I guess that this question could be deleted.
Thank you

Related

Approx(): Need at least two non-NA values to interpolate R

I am trying to use nnetar for some time series forecasting, and running into an issue when the data has repeating values (i.e. the same counts observed in a time period). To reproduce the error I have created a list of values and replaced the first 10 values with a 0:
dummy.ls <- runif(n=80)
for(i in 1:10)
dummy.ls[i] <- 0
fit <- nnetar(dummy.ls, lambda=0)
When running the nnetar function I receive the following error:
Error in approx(idx, x[idx], tt, rule = 2) :
need at least two non-NA values to interpolate
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
I see similar errors in other questions, but unsure how to avoid the error?

Plotting data in R: Error in plot.window(...) : need finite 'xlim' values

Trying to plot some data in R - I am a basic user and teaching myself. However, whenever I try to plot, it fails, and I am not sure why.
> View(Pokemon_BST)
> Pokemon_BST <- read.csv("~/Documents/Pokemon/Pokemon_BST.csv")
> View(Pokemon_BST)
> plot("Type_ID", "Gender_ID")
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
5: In min(x) : no non-missing arguments to min; returning Inf
6: In max(x) : no non-missing arguments to max; returning -Inf
This is my code, but I thought it might be an issue with my .csv file? I have attributed numbers to the "Type_ID" and "Gender_ID" columns. Type_ID has values between 1-20; Gender_ID has 1 for male, 2 for female, and 3 for both. I should state that both ID columns are just made of numeric values. Nothing more.
I then tried using barplot function. This error occurred:
> barplot("Gender_ID", "Type_ID")
Error in width/2 : non-numeric argument to binary operator
In addition: Warning message:
In mean.default(width) : argument is not numeric or logical: returning NA
There are no missing values, no characters within these columns, nothing that SHOULD cause an error according to my basic knowledge. I am just not sure what is going wrong.
To me it seems as you are giving the plot function the wrong inputs.
For the x and y axis plot expects numeric values and you are only providing a single string. The function does not know that the "Type_ID" and "Gender_ID" come from the Pokemon_BST data frame.
To reach your data you must tell R where the object comes from. You do this by opening square brackets behind the object you want to access and write the names of the objects to be accessed into it.
View(Pokemon_BST)
Pokemon_BST <- read.csv("~/Documents/Pokemon/Pokemon_BST.csv")
# Refer to the object
plot(Pokemon_BST["Type_ID"], Pokemon_BST["Gender_ID"])
# Sould also work now
barplot(Pokemon_BST["Gender_ID"], Pokemon_BST["Type_ID"])
See also here for a introduction on subsetting in R
The problem is how you're passing the values to the plot function. In your code above, "Gender_ID" is just some string and the plot function doesn't know what to do with that. One way to plot your values is to pass the vectors Pokemon_BST$Gender_ID and Pokemon_BST$Type_ID to the function.
Here's a sample dataframe with the plot you were intending.
Pokemon_BST <- data.frame(
Type_ID = sample(1:20, 10, replace = TRUE),
Gender_ID = sample(1:3, 10, replace = TRUE))
plot(Pokemon_BST$Gender_ID, Pokemon_BST$Type_ID)

nonlinear least squares troubleshooting

I am trying to run a nonlinear least squares regression in R and keep coming across the same error message which I can't seem to fix.
My function so far:
nls(y ~ 1033.89+(2461*cos*(2*3.14*(t-18)/24)),
data=data.frame, start=list(x=1, y=1))
where t=c(1:24) and data.frame contains x and y variables of equal length.
This error message continues to pop up:
Error in parse(text = x, keep.source = FALSE) :
:2:0: unexpected end of input
1: ~
^
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
Any suggestions?

LCP Generation Error

I've been trying to generate an LCP network between various points. I've had some success with some of my data sets but other sets cause an error to occur whenever I try to run the function. The data all follows the same format and reside in the same CRS so I don't understand what the issue is. I've tried a few workarounds but nothing has taken so far. I've included the basic script I use.
library(rgdal)
library(gdistance)
TRI<-raster("pathway.tif")
points<-readOGR("pathway.shp")
cost<-transition(TRI,sum,8)
LCP<-shortestPath(cost,points[1,],points[-1,],output="SpatialLines")
These arguments have worked for some parts of my dataset, but several of them show the following error message after I input the last line above and I'm not sure what the fix is as I'm pretty new to R:
Error in validObject(.Object) :
invalid class “SpatialLines” object: bbox should never contain infinite values
In addition: Warning messages:
1: In .Call("R_igraph_get_shortest_paths", graph, as.igraph.vs(graph, :
At structural_properties.c:4517 :Couldn't reach some vertices
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
4: In min(x) : no non-missing arguments to min; returning Inf
5: In max(x) : no non-missing arguments to max; returning -Inf
Any help or advice is greatly appreciated. Thanks!
This is not a reproducible example. It seems that you are creating some unconnected components in your TransitionLayer. Check the gdistance vignette for ways to avoid and detect this. See page 8 of https://www.jstatsoft.org/article/view/v076i13

R software, making boxplot, need finite 'ylim' value

> B<-subset(olympic,sport=="basketball")
> BM<-subset(B,sex=="M"
+ )
> boxplot(BM$height)
Error in plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs):
need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
This is what happened when I try to plot the graph. I'm new to R.
Just add ylim=c(0,300)) to your code
I see nothing wrong in the command though it can be shortened to:
> BM <- subset(olympic,sport=="basketball" & sex == 'M')
> boxplot(BM$height)
The error that you are getting might be because of the fact that data.frame BM has zero rows.
I would recommend you to please check the case of values for sport (i.e. whether in the dataset, 'Basketball' is present and you are searching for 'basketball')

Resources