simoncarrignon / mixed-transmission

GNU General Public License v3.0
1 stars 0 forks source link

Social Learning Notes #7

Closed ercrema closed 12 months ago

ercrema commented 1 year ago

Structure

Horizontal Transmission

Selects individuals of 'same' generation, i.e. absolute age difference of threshold years. What is threshold?

Oblique Transmission vs Mother/Father in law transmission

Do we want to keep oblique transmission as something separate? Or do we want to consider just parent-in-law? In the latter case there is no transmission of this type before marriage

ercrema commented 1 year ago

Sexual Bias

I am writing now the submodule for sexual bias in the transmission. The current implementation calculates the probability of adopting variant 1 (the new trait) as follow:

For example:

sex.teacher = c(0,0,0,0,1,1) # sex of the potential teacher
trait.teacher = c(1,1,1,0,0,1) #cultural trait of the potential teacher

# if s=0 (sexual bias favouring female parents) 
s=0
sum(abs(sex.teacher+(s-1))*trait.teacher) / sum(abs(sex.teacher+(s-1))*rep(1,length(trait.teacher)))

# if s=1 (sexual bias favouring male parents)
s=1
sum(abs(sex.teacher+(s-1))*trait.teacher) / sum(abs(sex.teacher+(s-1))*rep(1,length(trait.teacher)))

# if s=0.5 (no sexual bias)
s=0.5
sum(abs(sex.teacher+(s-1))*trait.teacher) / sum(abs(sex.teacher+(s-1))*rep(1,length(trait.teacher)))

This approach however does not care about the sex of the focal agent, a female or male agent has the same probability of adopting a particular variant nor makes the case of traits that are exclusively possessed by male or female individuals.

simoncarrignon commented 1 year ago

Have you don that already? Cause I wrote a function "sexbiascopy" in the file R/reproduction.R that I thought was doing the right thigns:


#' Sex-biased copying#'
#' This function performs sex-biased copying based on bias proba
#'
#' @param ta A vector of values selected with proba 1-sb
#' @param tb A vector of values selected with proba sb
#' @param sb A numeric vector of probabilities (between 0 and 1) indicating the bias  for each traits
#' @return A vector of values selected from `ta` or `tb` based on the bias condition.
#' @examples
#' sexbiascopy(c(t1=0,t2=0,t3=1), c(1,1,0), c(0.1,0.9,0.5))
#' barplot(apply(replicate(100,sexbiascopy(c(t1=0,t2=0,t3=1),c(1,1,0),c(.1,.9,.5))),1,table),legend=T)
#' @export
sexbiascopy <- function(ta,tb,sb){

    stopifnot(length(ta)==length(tb),length(tb)==length(sb))
    sexbias=runif(length(sb))<sb #if bias is only 0 1 runif useless, maye save some time not doing it?
    ifelse(sexbias,tb,ta)
}

Who get the probability s vs 1-s is determined before, in the function vertical in the file R/socialLearning.R not as ellegant as your solution, I did a ifelse... I have been intensively doing stuff the last three days as I also got a version of the whole code based on arrays, way faster and that I know plan to build around ; and didn't see your issue before now :(

simoncarrignon commented 12 months ago

Handy function to wrire @ercrema are the horizontal/oblique learning.

I have been thinking alot about it but I am still unsure what is the best way to do it:

a function General functionL "social_learning(population,traitsparameters,time=c("pre","post"),pathway=c("h","v")...)" (where '...' are other parameters specifics to pathway/time of learing) Which will take care of all cases out of the main thus the main will look like:


for i in time:
  population=rbind(population,birth())
  for( p in  c("h","v")):
       population[,"traits"]= social_learning( population,tp,time="post",pathway=p)

  population=marriage(population)
  for( p in  c("h","v")):
       population[,"traits"]= social_learning( population,tp,time="post",pathway=p)

  population=death(population)
}

or separate the functions:


for i in time:
  population=rbind(population,birth())
  population[,"traits"]=horizontal_learning( population,tp,time="pre")
  population[,"traits"]=oblique_learning( population,tp,time="pre")

  population=marriage(population)
  population[,"traits"]=horizontal_learning( population,tp,time="pre")
  population[,"traits"]=oblique_learning( population,tp,time="post")

  population=death(population)
} 

If you want to try to work on that @ercrema feel free to go for whatever directions.

Things available and useful for now are:

You can initialise tp using:

z=5
neutraltraitsParam=initNeutralTraitsPathways(z = z)
neutraltraitsParam$s=c(0,0,0,1,1)
neutraltraitsParam$pre[,"v"]=c(1,1,1,0,0)
neutraltraitsParam$post[,"h"]=c(1,0,1,0,1)

And population using:

population=cbind(newpop(N,age="random"),initNeutralTraits(N,z)) #initNeutralTraists(N,z) creaite a N*z array of 0 and 1

I realised that we should have used discussion for all that ; they look way more appropriate for this kind of dialogue!