## errorProb function: Generate error probabilities ## Returns total number of errors ## Arg 1: Number of samples for Monte Carlo ## Arg 2: Number of non-zero representational elements in underlying form ## Arg 3: Number of non-zero representational elements in target surface representation that are distinct from error ## Arg 4: Number of non-zero representational elements in error surface representation that are distinct from target ## Arg 5: Harmony advantage of target over error ## Arg 6: Standard deviation of randomly distributed noise ## Returns total number of errors ## NOTE to use a different probability distribution, alter the rnorm statements in the code below. errorProb.fnc = function (sampleNumber, underlying, uniqueTarget, uniqueError, common, harmonyAdvantage, sdNoise) { errorCount = 0 # count number of errors ## Calculate number of markedness weights that make a unique contribution to target and error harmony if(uniqueTarget+common > 1){ if(common>1){ markNTarget = length(combn(uniqueTarget+common,2,simplify=F)) -length(combn(common,2,simplify=F)) }else markNTarget = length(combn(uniqueTarget+common,2,simplify=F)) }else markNTarget = 0 if(uniqueError+common > 1){ if(common>1){ markNError = length(combn(uniqueError+common,2,simplify=F)) -length(combn(common,2,simplify=F)) }else markNError = length(combn(uniqueError+common,2,simplify=F)) }else markNError = 0 for (j in c(1:sampleNumber)) { targetHarmony = sum (rnorm(underlying*uniqueTarget,0,sdNoise)) # for each faithfulness weight that makes a unique contribution to the target, generate a random disruption targetHarmony = targetHarmony + 2*sum(rnorm(markNTarget,0,sdNoise)) # for each markedness weight that makes a unique contribution to the target, generate a random disruption errorHarmony = sum (rnorm(underlying*uniqueError,0,sdNoise)) # for each faithfulness weight that makes a unique contribution to the error, generate a random disruption errorHarmony = errorHarmony + 2*sum(rnorm(markNError,0,sdNoise)) # for each markedness weight that makes a unique contribution to the target, generate a random disruption if (-harmonyAdvantage > (targetHarmony-errorHarmony)) # if conditions of Corollary 2 are met, error has occurred errorCount = errorCount + 1 } return (errorCount) # return total number of errors }