{"action":"opened","issue":{"url":"https://api.github.com/repos/James-Thorson/VAST/issues/128","repository_url":"https://api.github.com/repos/James-Thorson/VAST","labels_url":"https://api.github.com/repos/James-Thorson/VAST/issues/128/labels{/name}","comments_url":"https://api.github.com/repos/James-Thorson/VAST/issues/128/comments","events_url":"https://api.github.com/repos/James-Thorson/VAST/issues/128/events","html_url":"https://github.com/James-Thorson/VAST/issues/128","id":351319993,"node_id":"MDU6SXNzdWUzNTEzMTk5OTM=","number":128,"title":"VAST 5.2.0 estimation fail","user":{"login":"mahaltuch","id":23059472,"node_id":"MDQ6VXNlcjIzMDU5NDcy","avatar_url":"https://avatars1.githubusercontent.com/u/23059472?v=4","gravatar_id":"","url":"https://api.github.com/users/mahaltuch","html_url":"https://github.com/mahaltuch","followers_url":"https://api.github.com/users/mahaltuch/followers","following_url":"https://api.github.com/users/mahaltuch/following{/other_user}","gists_url":"https://api.github.com/users/mahaltuch/gists{/gist_id}","starred_url":"https://api.github.com/users/mahaltuch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mahaltuch/subscriptions","organizations_url":"https://api.github.com/users/mahaltuch/orgs","repos_url":"https://api.github.com/users/mahaltuch/repos","events_url":"https://api.github.com/users/mahaltuch/events{/privacy}","received_events_url":"https://api.github.com/users/mahaltuch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-16T18:33:55Z","updated_at":"2018-08-16T18:33:55Z","closed_at":null,"author_association":"NONE","body":"I am working on getting VAST (V5.2.0) up and running with NWFSC survey data and am getting the following error during the estimation: \r\n\r\nError in solve.default(h, g) : \r\n  system is computationally singular: reciprocal condition number = 1.50334e-16\r\n\r\nThis looks like a TMB problem?\r\n\r\nThe script is here: \r\n\r\n#### Set inputs\r\nin_species <- \"Anoplopoma fimbria\"\r\nin_maxyear <- 2017\r\n# Logical if you want pass as catchability covariate\r\nin_usepass <- TRUE\r\n#strata limits, run model but then calculate area specific indices\r\n(strata.limits <- data.frame(\r\n  \"STRATA\" = c(\"Coastwide\",\"CA\",\"OR\",\"WA\"),\r\n  \"north_border\" = c(49.0, 42.0, 46.0, 49.0),\r\n  \"south_border\" = c(32.0, 32.0, 42.0, 46.0),\r\n  \"shallow_border\" = c(55, 55, 55, 55),\r\n#  'middle_border' = c(183, 183, 183, 183),\r\n  \"deep_border\" = c(1280, 1280, 1280, 1280)\r\n  ))\r\n#### Inputs you might want to change\r\nsetwd(\"C:\\\\Sablefish2019\\\\Data\\\\NWFSCSurveyIndex\")\r\nHomeDir <- getwd()\r\n# Number of \"knots\" used when Method=\"Mesh\"\r\nn_x <- 250\r\n# Distribution specification\r\nObsModel = c(2, 1)\r\n#ObsModel <- c(2, 0)\r\n#ObsModel = c(1,0) #lognormal errors\r\n\r\n# =============================================\r\nrequire(VAST)\r\nlibrary(maps)\r\nlibrary(mapdata)\r\n#install.packages(\"INLA\")\r\nlibrary(INLA)\r\n\r\nSablefish <- JRWToolBox::dataWareHouseTrawlCatch(Species = \"Anoplopoma fimbria\",\r\n          project = c('WCGBTS.Combo'))\r\nData_Set <- Sablefish\r\n\r\n# Version\r\n(Version <- gsub(\"\\\\.cpp\", \"\", tail(list.files(R.home(\r\n  file.path(\"library\", \"VAST\", \"executables\"))), 1)))\r\n\r\n#define the spatial resolution for the model, and whether to use a grid or mesh approximation\r\nMethod = c(\"Grid\", \"Mesh\", \"Spherical_mesh\")[2]\r\ngrid_size_km = 25     # Value only matters if Method=\"Grid\"\r\nKmeans_Config = list( \"randomseed\"=1, \"nstart\"=100, \"iter.max\"=1e3 )   # Controls K-means algorithm \r\n\r\n# Model settings\r\nFieldConfig = c(\"Omega1\"=1, \"Epsilon1\"=1, \"Omega2\"=1, \"Epsilon2\"=1)\r\nRhoConfig = c(\"Beta1\"=0, \"Beta2\"=0, \"Epsilon1\"=0, \"Epsilon2\"=0)\r\nOverdispersionConfig = c(\"Delta1\"=1, \"Delta2\"=1)\r\n\r\n#outputs calculated after model runs, essentially reports to create\r\nOptions =  c(\"SD_site_density\"=0, \"SD_site_logdensity\"=0, \"Calculate_Range\"=1, \"Calculate_evenness\"=0, \"Calculate_effective_area\"=1, \"Calculate_Cov_SE\"=0,\r\n             \"Calculate_Synchrony\"=0, \"Calculate_Coherence\"=0)\r\n\r\nsetwd(HomeDir)  # Make sure that the working directory is back where it started\r\n\r\n#region that tells software which grid to use\r\nRegion = \"California_current\"\r\n\r\n#save files setting\r\n# DateFile = paste0(getwd(),\"/VAST_output/\")  # Simple, but requires manually changing the directory to save different runs\r\n(DateFile <- file.path(HomeDir,\r\n  paste0(\"VAST_output_\", Sys.Date(), \"_\", gsub(\" \", \"\", in_species),\r\n    \"_nx=\", n_x, .Platform$file.sep)))\r\ndir.create(DateFile)\r\n\r\n#save all settings\r\n# Record = ThorsonUtilities::bundlelist( c(\"Data_Set\",\"Version\",\"Method\",\"grid_size_km\",\"n_x\",\"FieldConfig\",\"RhoConfig\",\"OverdispersionConfig\",\"ObsModel\",\"Kmeans_Config\") )\r\n# save( Record, file=file.path(DateFile,\"Record.RData\"))\r\n# capture.output( Record, file=paste0(DateFile,\"Record.txt\"))\r\n\r\n#set up data frame from data set\r\nData_Geostat = data.frame(\r\n  Catch_KG = Data_Set[, grep(\"kg\", colnames(Data_Set))],\r\n  Year = Data_Set$Year, Vessel = paste(Data_Set$Vessel,Data_Set$Year,sep=\"_\"),\r\n             AreaSwept_km2 = Data_Set$Area_Swept_ha/100, Lat =Data_Set$Latitude_dd,\r\n             Lon = Data_Set$Longitude_dd, Pass = Data_Set$Pass - 1.5)\r\n\r\nData_Geostat = na.omit( Data_Geostat )\r\n\r\n# shows data being used, read this document\r\npander::pandoc.table( Data_Geostat[1:6,], digits=3 )\r\n\r\n#extrapolation grid\r\nExtrapolation_List = SpatialDeltaGLMM::Prepare_Extrapolation_Data_Fn( Region=Region, strata.limits=strata.limits )\r\n\r\n#derived objects for spatio-temporal estiamtion\r\nSpatial_List = SpatialDeltaGLMM::Spatial_Information_Fn( grid_size_km=grid_size_km, n_x=n_x, Method=Method, Lon=Data_Geostat[,\"Lon\"], Lat=Data_Geostat[,\"Lat\"],\r\n                         Extrapolation_List=Extrapolation_List, randomseed=Kmeans_Config[[\"randomseed\"]], nstart=Kmeans_Config[[\"nstart\"]], iter.max=Kmeans_Config[[\"iter.max\"]],\r\n                         DirPath=DateFile, Save_Results=FALSE )\r\n\r\n# Add knots to Data_Geostat\r\nData_Geostat = cbind( Data_Geostat, knot_i = Spatial_List$knot_i )\r\nhead(Data_Geostat)\r\n\r\n#build model, this is where you could specify new covariates using Data_Fn...use Pass\r\n  DateFile <- gsub(\"nx\", \"Pass_nx\", DateFile)\r\n  dir.create(DateFile)\r\n  Q_ik <- as.matrix(Data_Geostat[, \"Pass\", drop=F])\r\n#note, removed the -1 after vessel, why was this here?\r\n  TmbData = VAST::Data_Fn(\"Version\"=Version, \"FieldConfig\"=FieldConfig, \"OverdispersionConfig\"=OverdispersionConfig, \"RhoConfig\"=RhoConfig, \"ObsModel\"=ObsModel,\r\n                    \"c_i\"=rep(0,nrow(Data_Geostat)), \"b_i\"=Data_Geostat[,\"Catch_KG.Total_sp_wt_kg\"], \"a_i\"=Data_Geostat[,\"AreaSwept_km2\"], \"v_i\"=as.numeric(Data_Geostat[,\"Vessel\"])-1,\r\n                    \"s_i\"=Data_Geostat[,\"knot_i\"]-1, \"t_i\"=Data_Geostat[,\"Year\"], \"a_xl\"=Spatial_List$a_xl, Q_ik = Q_ik, \"MeshList\"=Spatial_List$MeshList, \"GridList\"=Spatial_List$GridList,\r\n                    \"Method\"=Spatial_List$Method, \"Options\"=Options )\r\n\r\n################\r\n# Do the estimation\r\n################\r\n\r\n# Build tmb object\r\nTmbList = VAST::Build_TMB_Fn(\"TmbData\"=TmbData, \"RunDir\"=DateFile, \"Version\"=Version, \"RhoConfig\"=RhoConfig, \"loc_x\"=Spatial_List$loc_x, \"Method\"=Method)\r\nObj = TmbList[[\"Obj\"]]\r\n\r\n# Run optimizer with Newton steps to improve convergence\r\nOpt = TMBhelper::Optimize( obj=Obj, lower=TmbList[[\"Lower\"]], upper=TmbList[[\"Upper\"]], getsd=TRUE,\r\n    newtonsteps=2, savedir=DateFile, bias.correct=TRUE,\r\n    bias.correct.control = list(sd = FALSE, split = NULL, nsplit = 1,\r\n      vars_to_correct = \"Index_cyl\"))\r\n\r\n"}}
{"actor":{"display_login":"mahaltuch"}}