df2<-subset(df, !is.na(Estimate)&r_sq >= 0.5  & !is.na(Nat_change)&length_time >=10 & System!="Marine" &Specific_location == 1  & !is.na(Bodymass) )

nrow(df2)
## [1] 850
species<-"Capra_ibex"

prob_scenario<-c(0.5,0.5)    #need to check this

noise<-0.95     #need to check this

stages<-comadre$matrixClass[keep][[1]]$MatrixClassAuthor
stagesf<-stages[1:3]

list_names_matrices<-colnames(matrices)

sumweight<-rep(1, length(stages)) #weight of stages  - should be equal for all mine just in plants seed not included in calculating population sizes - or if you wanted to just calculate the female population it would be c(1,1,1,0,0,0)
#sumweightf<-c(1,1,1)

transition_affected_niche<-"all"    #which parts of the matrix are affected by the niche values

transition_affected_env <- "all"

transition_affected_demogr <- "all"

env_stochas_type<-"normal"   #can also be lognormal

matrices_var <- matrix(0.01, ncol = 1, nrow = nrow(matrices), dimnames = list(NULL, "sd")) #standard deviation of matrices

proportion_initial<- rep(1/length(stages), length(stages)) #proportion of population in each stage - no idea what this should be and will likely have a big impact on results! - just doing eqaul splits for now
#proportion_initialf<- c(1/3,1/3,1/3)

density_individuals <- 1   #also compulsory not sure what best value would be

K<-NULL

K_weight<-FALSE

fraction_SDD <- 0.05  #short distance dispersal

#fraction_LDD_mine <- 0.05 #long distance dispersal

Minimal Setup

demoniche_setup(modelname = "RPyran",Populations = Populations, matrices_var = matrices_var,matrices = matrices,
                stages = stages, proportion_initial = proportion_initial,density_individuals = density_individuals,
                no_yrs = 80, sumweight =sumweight)   #important to include sumweight, I think the default is FALSE but that causes the population to be 0 in all years

RPyran_min_run <- demoniche_model(modelname = "RPyran", Niche = FALSE, Dispersal = FALSE, repetitions = 1,foldername = "RPyran_minimal")
## [1] Starting projections for repetition: 1
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Calculating summary values
## [1]     All repetitions completed!
RPyran_min_run[,"Meanpop","Reference_matrix"]
##   year1   year2   year3   year4   year5   year6   year7   year8   year9 
##    1971    2151    2340    2529    2736    2961    3213    3492    3798 
##  year10  year11  year12  year13  year14  year15  year16  year17  year18 
##    4149    4527    4950    5391    5895    6435    7047    7695    8433 
##  year19  year20  year21  year22  year23  year24  year25  year26  year27 
##    9216   10098   11061   12132   13302   14589   16011   17568   19269 
##  year28  year29  year30  year31  year32  year33  year34  year35  year36 
##   21150   23211   25488   27990   30726   33750   37071   40734   44748 
##  year37  year38  year39  year40  year41  year42  year43  year44  year45 
##   49158   54009   59346   65205   71658   78741   86535   95121  104526 
##  year46  year47  year48  year49  year50  year51  year52  year53  year54 
##  114894  126288  138807  152568  167715  184356  202662  222786  244908 
##  year55  year56  year57  year58  year59  year60  year61  year62  year63 
##  269226  295974  325377  357705  393255  432324  475281  522531  574461 
##  year64  year65  year66  year67  year68  year69  year70  year71  year72 
##  631566  694341  763353  839241  922689 1014426 1115280 1226178 1348101 
##  year73  year74  year75  year76  year77  year78  year79  year80 
## 1482138 1629522 1791549 1969713 2165580 2380923 2617686 2878002

Maximal set up

demoniche_setup(modelname = "RPyran_max",Populations = Populations, Nichemap = nichemap,matrices = matrices, 
                matrices_var = matrices_var, noise = 0.1, prob_scenario = prob_scenario,stages = stages, 
                proportion_initial = proportion_initial, density_individuals = density_individuals, fraction_LDD = 0.05,                 fraction_SDD = 0.05, dispersal_constants = FALSE, transition_affected_niche = "all",
                transition_affected_demogr = "all", transition_affected_env = "all", env_stochas_type = "normal", no_yrs = 9, K = 10000, Kweight = FALSE, sumweight = sumweight)

RPyran_max_run <- demoniche_model(modelname = "RPyran_max", Niche = TRUE, Dispersal = FALSE, repetitions = 10,foldername = "RPyran_minimal")
## [1] Starting projections for repetition: 1
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 2
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 3
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 4
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 5
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 6
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 7
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 8
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 9
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Starting projections for repetition: 10
## [1] Projecting for scenario/matrix: Reference_matrix
## [1] Calculating summary values
## [1]     All repetitions completed!
RPyran_max_run[,"Meanpop","Reference_matrix"]
##  year1  year2  year3  year4  year5  year6  year7  year8  year9 year10 
##  848.2  453.6  262.2  174.6  128.4   98.8   74.9   56.9   42.0   32.8 
## year11 year12 year13 year14 year15 year16 year17 year18 year19 year20 
##   25.5   19.2   13.2    7.2    2.7    1.3    0.3    0.0    0.0    0.0 
## year21 year22 year23 year24 year25 year26 year27 year28 year29 year30 
##    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0 
## year31 year32 year33 year34 year35 year36 year37 year38 year39 year40 
##    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0 
## year41 year42 year43 year44 year45 year46 year47 year48 year49 year50 
##    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0 
## year51 year52 year53 year54 year55 year56 year57 year58 year59 year60 
##    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0 
## year61 year62 year63 year64 year65 year66 year67 year68 year69 year70 
##    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0 
## year71 year72 
##    0.0    0.0

which species are in both Comadre and LPI

##                                   Common_name Comadre_Matrices
## 1                            Northern goshawk                1
## 2                                     Cheetah                2
## 3                 Impala / Black-faced impala                4
## 4                           Common kingfisher                1
## 5                    Mallard / Common mallard                2
## 6                               Greylag goose                3
## 7                                        Gaur                2
## 8                            Northern muriqui               26
## 9                            Temminck's stint                2
## 10                                     Coyote                1
## 11                      Grey wolf / Gray wolf                4
## 12                                Alpine ibex                1
## 13                       White-faced capuchin               23
## 14                                Blue monkey               29
## 15                             Red deer / Elk                4
## 16     Greater snow goose / Lesser snow goose                7
## 17                                White stork               29
## 18                           Black rhinoceros                1
## 19                           Peregrine falcon               28
## 20 Mountain gorilla / Eastern lowland gorilla               42
## 21                     Eurasian oystercatcher                2
## 22                         White-tailed eagle                2
## 23                                Black stilt               16
## 24                                  Waterbuck                1
## 25                             Rock ptarmigan                8
## 26                              Snowshoe hare                6
## 27                           African elephant                1
## 28                           African wild dog                3
## 29                                       Lynx                2
## 30                      Yellow-bellied marmot               18
## 31                                 Black kite                1
## 32                                      Urial                7
## 33             Bighorn sheep / Mountain sheep               13
## 34                                    Leopard                3
## 35      North American deermouse / deer mouse                5
## 36              Desert warthog / Cape warthog                1
## 37                                      Koala                5
## 38                                    Raccoon                1
## 39                         Reindeer / Caribou                2
## 40                                Common tern                8
## 41                               Red squirrel                1
## 42                  Grizzly bear / Brown bear                2
## 43                                    Red fox               13
##    LPI_Populations
## 1                1
## 2                3
## 3                7
## 4                1
## 5                5
## 6                5
## 7                1
## 8                1
## 9                1
## 10               5
## 11               3
## 12              10
## 13               1
## 14               1
## 15               9
## 16               1
## 17               1
## 18              10
## 19               2
## 20               2
## 21               1
## 22               2
## 23               1
## 24               9
## 25               1
## 26               5
## 27              12
## 28               3
## 29               1
## 30               1
## 31               1
## 32               3
## 33               1
## 34               1
## 35               3
## 36               2
## 37               4
## 38               1
## 39               2
## 40               1
## 41               1
## 42               3
## 43               2