if (FALSE) {
# Not run
library(BoneProfileR)
path_Hedgehog <- system.file("extdata", "Erinaceus_europaeus_fem_2-1_small.png",
package = "BoneProfileR")
bone <- BP_OpenImage(file=path_Hedgehog)
bone <- BP_DetectBackground(bone=bone, analysis="logistic")
bone <- BP_DetectForeground(bone=bone, analysis="logistic")
bone <- BP_DetectCenters(bone=bone, analysis="logistic")
bone <- BP_EstimateCompactness(bone, analysis="logistic", cut.angle = 60)
bone <- BP_FitMLCompactness(bone, analysis="logistic", twosteps=TRUE)
plot(bone, type="observations+model", analysis="logistic")
par <- BP_GetFittedParameters(bone, analysis="logistic", ML=TRUE, return.all=FALSE)[, "mean"]
options(mc.cores=parallel::detectCores())
#############################################
# Periodic analysis
#############################################
bone <- BP_FitMLPeriodicCompactness(bone, analysis="logistic", control.optim=list(trace=2),
fitted.parameters=c(par, PSin=0.001, PCos=0.001,
SSin=0.001, SCos=0.001, MinSin=0.001, MinCos=0.001,
MaxSin=0.001, MaxCos=0.001), replicates.CI=2000)
analysisP <- BP_GetFittedParameters(bone, analysis="logistic", type="periodic",
ML=TRUE, return.all=FALSE)[, "mean"]
analysisP$par
plot(bone, type="periodic", parameter.name="compactness", col=rainbow(128))
plot(bone, type="periodic", parameter.name="compactness",
col=hcl.colors(12, "YlOrRd", rev = TRUE))
plot(bone, type="periodic", parameter.name="averagemodel")
plot(bone, type="periodic", parameter.name="P",
rgb(red = 0.7, green = 0.7, blue = 0.7, alpha = 0.2))
plot(bone, type="periodic", parameter.name="P", ylim=c(0, 1),
rgb(red = 0.7, green = 0.7, blue = 0.7, alpha = 0.2))
boneNoPeriodic <- BP_FitMLPeriodicCompactness(bone, analysis="logistic",
control.optim=list(trace=2),
fitted.parameters=par, replicates.CI=2000)
analysisNP <- BP_GetFittedParameters(boneNoPeriodic, analysis="logistic", ML=TRUE,
return.all=TRUE, type="periodic")
analysisNP$par
compare_AIC(PeriodicModel=analysisP,
NoPeriodicModel=analysisNP)
#############################################
# Note that the absolute likelihood is dependent on the number of angle cut
# Only models analyzed with the same number of angle cuts can be compared
dbinom(5, 10, prob=0.4, log=TRUE);
dbinom(2, 5, prob=0.4, log=TRUE)+dbinom(3, 5, prob=0.4, log=TRUE)
# But the likelihood difference between two models are not:
dbinom(5, 10, prob=0.4, log=TRUE)-dbinom(5, 10, prob=0.3, log=TRUE)
dbinom(2, 5, prob=0.4, log=TRUE)+dbinom(3, 5, prob=0.4, log=TRUE)-
dbinom(2, 5, prob=0.3, log=TRUE)-dbinom(3, 5, prob=0.3, log=TRUE)
}
Run the code above in your browser using DataLab