if (FALSE) {
# Not run:
library(BoneProfileR)
bone <- BP_OpenImage()
# or
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")
plot(bone, type="colors")
bone <- BP_DetectCenters(bone=bone, analysis="logistic")
plot(bone, type="3Dcolors")
bone <- BP_EstimateCompactness(bone, analysis="logistic")
bone <- BP_FitMLCompactness(bone, analysis="logistic")
plot(bone)
############################################
# Example with comparison between two models
############################################
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")
bone <- BP_FitMLCompactness(bone, analysis="logistic")
plot(bone)
plot(bone, type="observations")
plot(bone, type="observations+model", analysis=1)
fittedpar <- BP_GetFittedParameters(bone, analysis="logistic",
ML=TRUE, return.all = FALSE)[, "mean"]
bone <- BP_DuplicateAnalysis(bone, from="logistic", to="flexit")
bone <- BP_FitMLCompactness(bone,
fitted.parameters=c(fittedpar, K1=1, K2=1),
fixed.parameters=NULL, analysis="flexit")
compare_AIC(Logistic=BP_GetFittedParameters(bone, analysis="logistic",
ML=TRUE, return.all = TRUE),
Flexit=BP_GetFittedParameters(bone, analysis="flexit",
ML=TRUE, return.all = TRUE))
out4p <- plot(bone, type="observations+model", analysis="logistic")
out6p <- plot(bone, type="observations+model", analysis="flexit")
############################################
# Fit distribution using Bayesian model
############################################
bone <- BP_FitBayesianCompactness(bone, analysis="logistic", n.adapt=100)
# Test the output - New in version 3.2
plot(bone, type="mcmc", options.mcmc = list(what="LnL"))
#########################################################################
# Clearly the distribution is not stationary; the adaptation was too short
#########################################################################
bone <- BP_FitBayesianCompactness(bone, analysis="logistic", n.adapt=10000)
# Now it is ok
plot(bone, type="mcmc", options.mcmc = list(what="LnL"))
#########################################################################
# New in version 3.2
#########################################################################
plot(bone, type="mcmc", options.mcmc = list(what="Posterior",
xlim=c(0.025, 0.035), breaks=seq(from=0.025, to=0.035, by=0.001)),
parameter.name = "S")
plot(bone, type="mcmc", options.mcmc = list(what="MarkovChain",
ylim=c(0.02, 0.04)),
parameter.name = "S")
#########################################################################
# Check the priors and the output
#########################################################################
mcmc <- RM_get(x=bone, RMname="logistic", valuename = "mcmc")
priors <- mcmc$parametersMCMC$parameters
parameters <- as.parameters(mcmc, index="median")
#########################################################################
# Now it is ok. It can be used
#########################################################################
plot(bone, type="observations+model", CI="MCMC")
plot(bone, type="observations+model", CI="ML")
#########################################################################
#############################################
# Radial compactness
#############################################
bone <- BP_FitMLRadialCompactness(bone, progressbar=TRUE)
plot(bone, type="radial", parameter.name=c("P", "S"))
plot(bone, type="radial", parameter.name=c("P", "S", "Min", "Max"))
plot(bone, type="radial", parameter.name="observed.compactness")
plot(bone, type="radial", parameter.name="linearized.observed.compactness")
#############################################
# Periodic analysis
# This model can take 10 minutes to be fitted
# And still more if you use large replicates.CI value
#############################################
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)
plot(bone, type="periodic", parameter.name="compactness", col=rainbow(128))
plot(bone, type="periodic", parameter.name="compactness")
plot(bone, type="periodic", parameter.name="P", ylim=c(0, 1),
col=rgb(red = 0.7, green = 0.7, blue = 0.7, alpha = 0.2))
plot(bone, type="periodic", parameter.name="averagemodel")
}
Run the code above in your browser using DataLab