There is no nn$result.matrix in neuralnet in r - r

I did neuralnet in R
test_wocoal=sample(dim(df_wocoal)[1],8570)
sx=scale(df_wocoal);sx=as.data.frame(sx)
train=sx[-test_wocoal,];test=sx[test_wocoal]
n=names(train)
form=as.formula(paste('Primary_Air_Flow~',paste(n[!n %in% 'primary_Air_Flow'],collapse='+')))
nn=neuralnet(form,data=train,hidden=3,linear.output,err.fct="ce",stepmax=1e+08,threshold=0.01)
the ftn 'neuralnet' was ended sucessfully.
So, i was doing 'compute'
But, the R gave me a warnings.
pre=compute(nn,test[,-1])
Error in nrow[w]*ncol[w] :non-numeric argument to binary operator
In addition: Warning message:
In un.na(weights): in.na() applied to non-(list or vector) of type 'NULL'
So, i checked my data frame, but there is no NA(all cases are complete) and all columns are numeric.
I don't know why that error is comming
and, i checked component(?) in 'nn'
there is no 'result.matrix'.
'nn' has only 'numHiddenNodes','data','hidden','linear.output','err.fct','stepmax','threshold'
What problem is in here? How to solve it?

Related

Warning message within R function seems to make the function not work?

Using the syuzhet package in R, the following works but returns a warning message:
object <- get_text_as_string("path/name.txt")
When I put this in a function, it returns the same warning error but does NOT change the value of object:
gen <- function(file){
object <- get_text_as_string(file)
}
gen("path/name.txt")
This is the warning message, if it matters:
Warning message:
In readLines(path_to_file) :
incomplete final line found on 'path/name.txt'
...but again, I get that from get_text_as_string() when used outside of the function, but it DOES change the value of object.
Anyone have any advice? There must be something I don't understand about functions?
(I've looked for similar questions/answers, if I've missed the right one I'd be happy to just be directed there.)

How to solve- Error: (converted from warning)

I have been getting this error for the first time for commands that used to run well before:
# conversion from char to numeric:
as.numeric(df$col) -> df$col
Error: (converted from warning) NAs introduced by coercion
# running metafor
rma(yi, vi, data=r1s2)
Error: (converted from warning) Studies with NAs omitted from model fitting.
The issue must be with the R environment as these commands are running perfectly on a different computer. The only wrong I can think of is installing a package from GitHub or updating R a few hours ago. The only relevant answer I've found so far is also not working:
Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS="true")
This seems to be a warning level issue. If the warning level is 2, warnings become errors. From the documentation, my emphasis.
warn:
integer value to set the handling of warning messages. If warn is negative all warnings are ignored. If warn is zero (the default) warnings are stored until the top–level function returns. If 10 or fewer warnings were signalled they will be printed otherwise a message saying how many were signalled. An object called last.warning is created and can be printed through the function warnings. If warn is one, warnings are printed as they occur. If warn is two (or larger, coercible to integer), all warnings are turned into errors.
old_ops <- options(warn = 2)
warning("this is a warning")
#> Error in eval(expr, envir, enclos): (converted from warning) this is a warning
x <- "a"
as.numeric(x)
#> Error in eval(expr, envir, enclos): (converted from warning) NAs introduced by coercion
options(old_ops)
Created on 2022-06-25 by the reprex package (v2.0.1)
If you say that
The issue must be with the R environment as these commands are running perfectly on a different computer.
then check if you have a file named .RData in your R startup directory. If you have one, then you probably set the warning level in a previous session and now it is being restored every time you run R. Delete this file and this behavior will go away.
See also this SO post.

New to statnet in r, error in .Call message

I'm using statnet and R for the first time, and keep coming across this error message:
Error in .Call(getEdgeAttribute_R, el, attrname, na.omit, null.na, deleted.edges.omit) :
NULL value passed as symbol address
I have not had this problem in any other packages that I've used. And I have not been able to locate any other threads/questions with this error in statnet.
Any help and/or suggestions is greatly appreciated!

Error using treedata() from geiger package in R

I am trying to run the following lines of code:
tree <- read.nexus("~/Dropbox/Billfishes/Analysis/Phylogenies/Fish_12Tax_time_calibrated.tre");
characterTable <- read.csv("~/Dropbox/Billfishes/Analysis/CodingTableThresh95.csv", row.names = 1);
treeWData <- treedata(tree, characterTable, sort = T);
When I ran this code last week, it worked. I then updated all my packages as part of routine maintenance, and now I get this error:
Error in integer(max(oldnodes)) : vector size cannot be infinite
In addition: Warning message:
In max(oldnodes) : no non-missing arguments to max; returning -Inf
I've tried rolling back to previous versions of R (I'm currently running R version 3.4.0 in RStudio 1.0.143; geiger is version 2.0.6), reading the tree in as a Newick, and trying other tree files, always resulting in the same error. When I try using other tree and character datasets, I do not get the error.
Any ideas what this error means, and/or how to get this code to run without throwing this error?
After careful error checking, I discovered that the taxon names in the phylogeny file were separated by underscores, whereas the taxon names in the table used camel caps. Thus, the error was thrown because no taxa in the phylogeny mapped to the character table.

Seems like R can't see properly the variables in my function (pb pointsToMatrix)

I have created a function which run well on my local environment, but fail on the server.
function(dataset1,nom_col_lon1,nom_col_lat1,dataset2,nom_col_lon2,nom_col_lat2,nom_col_ID2){
require(geosphere)
mat.dist<- distm(dataset1[,c(nom_col_lon1,nom_col_lat1)], dataset2[,c(nom_col_lon2,nom_col_lat2)], fun=distHaversine)
lon=match(nom_col_lon2,colnames(dataset2))
dataset1$compLon=dataset2[,lon][apply(mat.dist,1,which.min)]
rm(lon)
lat=match(nom_col_lat2,colnames(dataset2))
dataset1$compLat=dataset2[,lat][apply(mat.dist,1,which.min)]
rm(lat)
ID=match(nom_col_ID2,colnames(dataset2))
dataset1$compID=dataset2[,ID][apply(mat.dist,1,which.min)]
dataset1$dist_min=apply(mat.dist,1,min)
rm(mat.dist)
return(dataset1)}
It works well on my local session, but when I call it on the server, I got this error:
ARCEP_SFR_2G=min_dist(ARCEP_SFR_2G,"lon","lat",ANFR_SFR_2G,"lon","lat","ID")
Error in .pointsToMatrix(p1) * toRad :
non-numeric argument to binary operator
In addition: Warning messages:
1: In .pointsToMatrix(x) : NAs introduced by coercion
2: In .pointsToMatrix(y) : NAs introduced by coercion
In the two dataset that I use, nom_col_lon and nom_col_lat are numeric. There is no NA. When I check the environment for min_dist, it's "global environment". Any idea of what could be the problem?
EDIT:
When I run
mat.dist<- distm(ARCEP_SFR_2G[,c("lon","lat")], ANFR_SFR_2G[,c("lon","lat")], fun=distHaversine)
it works well. The problem happens only when I call the function.
EDIT2:
Exemple of dataset:
Technologie=c("2G","3G")
Operateur=c("Ope1","Ope2")
lat=c(46.2,46.1)
lon=c(5.34,5.51)
ID=c("ID1","ID2")
x=as.data.table(cbind(Technologie,Operateur,lat,lon,ID))
x$lat=as.numeric(x$lat)
x$lon=as.numeric(x$lon)
The server is a Linux server. My local session is under windows.

Resources