Title: | Normalized Spatial Intensity Correlation |
---|---|
Description: | Calculate the colocalization index, NSInC, in two different ways as described in the paper (Liu et al., 2019. Manuscript submitted for publication.) for multiple-species spatial data which contain the precise locations and membership of each spatial point. The two main functions are nsinc.d() and nsinc.z(). They provide the Pearson’s correlation coefficients of signal proportions in different memberships within a concerned proximity of every signal (or every base signal if single direction colocalization is considered) across all (base) signals using two different ways of normalization. The proximity sizes could be an individual value or a range of values, where the default ranges of values are different for the two functions. |
Authors: | Jiahui Xu, Xueyan Liu, Lin Li, Cheng Cheng, Hui Zhang |
Maintainer: | Hui Zhang <[email protected]> |
License: | GPL-3 |
Version: | 1.0.2 |
Built: | 2024-11-10 03:59:37 UTC |
Source: | https://github.com/cran/colocalization |
nsinc.d
is used to calculate the Pearson's correlation coefficient of the average proportion densities with complete spatial randomness (CSR) as reference of two types of signals in a specified proximity of all signals or all signals of interested type (or base signals) as the colocalization index for a whole image. If a range of proximity sizes are concerned, the nsinc.d
will take the average of the index values over the range. In the case of multiple-species data, the average of index values of all pairs at each proximity size is taken as the index for the image at that size of neighborhood.
nsinc.d(data, membership, dim = 2, r.min = NULL, r.max = NULL, r.count = NULL, r.adjust = NULL, box = NULL, edge.effect = TRUE, strata = FALSE, base.member = NULL, r.model = "full", ...)
nsinc.d(data, membership, dim = 2, r.min = NULL, r.max = NULL, r.count = NULL, r.adjust = NULL, box = NULL, edge.effect = TRUE, strata = FALSE, base.member = NULL, r.model = "full", ...)
data |
a data frame (or object coercible by as.data.frame to a data frame) containing at least the columns |
membership |
a string describing the column name in the |
dim |
an integer either |
r.min |
the minimum proximity size that the user identifies as colocalization of signals. It should be numeric. If |
r.max |
the maximum proximity size that the user identifies as colocalization of signals. It should be numeric. If |
r.count |
the total count of the series of proximity sizes between |
r.adjust |
a small adjustment for |
box |
a one-row data frame describing the study region which must contain columns |
edge.effect |
a logical value showing whether the edge effect should be corrected. By default it should be corrected otherwise the results are not accurate. |
strata |
a logical value showing whether the user wants to consider single-direction or bi-direction colocalization. By default |
base.member |
one level of the memberships that is designated as the base. It works only when |
r.model |
equals either |
... |
Parameters passed to |
The function calculates the average proportion density with CSR as reference of two types of signals in a specified r neighborhood with edge effect corrected of all signals or all base signals if strata = TRUE
is specified, then obtains the Pearson correlation coefficients of each pair of channels and average them among all pairs at each r in the r series from r.min
to r.max
. In the case of multiple-species data, the average of index values of all pairs at each proximity size is taken as the index for the image at that size of neighborhood. The index for the whole image is named as NSInCd or NSInC of type d. The index will be close to 1 if signals are colocalized, 0 if random and -1 if dispersed. The function can deal with 2D or 3D data.
If the users have their specific proximity size, then they are encouraged to specify r.model = "other"
, and same values for r.min
and r.max
.
nsinc.d
returns all colocalization index at each separate proximity size r, and the average colocalization index across all r's, the data that the colocalization index is calculated from, the study region, i.e., the carrying box, the original and normalized proportions of each type of signals in an r neighborhood of all (base) signals, the r series, and some summary information:
method |
"nsinc.d" |
input.data.summary |
a list containing the number of membership levels and the signal counts in each channel or membership of the input data. |
post.data.summary |
a list showing the number of membership levels and signal counts in each channel of the data after removal of signals located outside the specified box by the user. If there is no signals excluded, then |
r.summary |
a data frame listing the |
strata |
a list showing the default setting of strata or the specified strata by the user. It also presents the base membership used in the function if |
edge.effect |
a data frame containing a logical value indicating whether edge effect is corrected or not. |
index.all |
a data frame showing the colocalization index of d-type at each r. |
index |
the averaged colocalization index of d-type across all r's. |
post.data |
a data frame representing the data after removal of signals located outside the specified box by the user. If there is no signal excluded, then |
study.region |
the carrying box with the size of buffer width in each dimension. |
P.all |
the data frame showing all original and normalized proportions of each type of signals in an r-neighborhood around every (base) signal. Rows are (base) signals and columns are all memberships and r's. |
r |
the r series for which the colocalization indices are calculated. |
Xueyan Liu, Jiahui Xu, Cheng Cheng, Hui Zhang.
Liu, X., Xu, J., Guy C., Romero E., Green D., Cheng, C., Zhang, H. (2019). Unbiased and Robust Analysis of Co-localization in Super-resolution Images. Manuscript submitted for publication.
## A simulated 2D example data. set.seed(1234) x <- runif(300, min = -1, max = 1) y <- runif(300, min = -1, max = 1) red <- data.frame(x,y, color = "red") x <- runif(50, min = -1, max = 1) y <- runif(50, min = -1, max = 1) green <- data.frame(x,y, color = "green") mydata <- rbind(red,green) plot(mydata$x,mydata$y,col = mydata$color) mydata.results <- nsinc.d(data = mydata, membership = "color", dim = 2) mydata.results$index.all mydata.results$index ## A simulated 3D example data. data("twolines") library("rgl") plot3d(twolines[,c("x","y","z")], type='s', size=0.7, col = twolines$membership) aspect3d("iso") twolines.results <- nsinc.d(data = twolines, membership = "membership", dim = 3, r.model = "r.med") twolines.results$index
## A simulated 2D example data. set.seed(1234) x <- runif(300, min = -1, max = 1) y <- runif(300, min = -1, max = 1) red <- data.frame(x,y, color = "red") x <- runif(50, min = -1, max = 1) y <- runif(50, min = -1, max = 1) green <- data.frame(x,y, color = "green") mydata <- rbind(red,green) plot(mydata$x,mydata$y,col = mydata$color) mydata.results <- nsinc.d(data = mydata, membership = "color", dim = 2) mydata.results$index.all mydata.results$index ## A simulated 3D example data. data("twolines") library("rgl") plot3d(twolines[,c("x","y","z")], type='s', size=0.7, col = twolines$membership) aspect3d("iso") twolines.results <- nsinc.d(data = twolines, membership = "membership", dim = 3, r.model = "r.med") twolines.results$index
nsinc.z
is used to calculate the Pearson's correlation coefficient of the signal proportions of two channels with a z-score normalization based on complete spatial randomness (CSR) in a specified proximity of all signals or all signals of interested type as the colocalization index for a whole image. If a range of proximity sizes are concerned, the nsinc.z
will take the average of the index values over the range. In the case of multiple-species data, the average of index values of all pairs at each proximity size is taken as the index for the image at that size of neighborhood.
nsinc.z(data, membership, dim = 2, r.min = NULL, r.max = NULL, r.count = NULL, r.adjust = NULL, box = NULL, edge.effect = TRUE, strata = FALSE, base.member = NULL, r.model = "full", ...)
nsinc.z(data, membership, dim = 2, r.min = NULL, r.max = NULL, r.count = NULL, r.adjust = NULL, box = NULL, edge.effect = TRUE, strata = FALSE, base.member = NULL, r.model = "full", ...)
data |
a data frame (or object coercible by as.data.frame to a data frame) containing at least the columns |
membership |
a string describing the column name in the |
dim |
an integer either |
r.min |
the minimum proximity size that the user identifies as colocalization of signals. It should be numeric. If |
r.max |
the maximum proximity size that the user identifies as colocalization of signals. It should be numeric. If |
r.count |
the total count of the series of proximity sizes between |
r.adjust |
a very small adjustment for |
box |
a one-row data frame describing the study region which must contain columns |
edge.effect |
a logical value showing whether the edge effect should be corrected. By default it should be corrected otherwise the results are not accurate. |
strata |
a logical value showing whether the user wants to consider single-direction or bi-direction colocalization. By default |
base.member |
one level of the memberships that is designated as the base. It works only when |
r.model |
equals either |
... |
Parameters passed to |
The function calculates the proportion of two types of signals normalized by a z-score under CSR in a specified r neighborhood with edge effect corrected of all signals or all base signals if strata = TRUE
is specified, then obtains the Pearson correlation coefficients of each pair of channels and average them among all pairs at each r in the r series between r.min
to r.max
. In the case of multiple-species data, the average of index values of all pairs at each proximity size is taken as the index for the image at that size of neighborhood. The index for the whole image is named as NSInCz or NSInC of type z. The index will be close to 1 if signals are colocalized, 0 if random and -1 if dispersed. The function can deal with 2D or 3D data.
If the users have their specific proximity size, then they are encouraged to specify r.model = "other"
, and values of r.min
and r.max
.
The difference from nsinc.d
is the normalization of the signal proportions. The z-type normalization has no heterogeneity under CSR caused by the edge effects related to the locations of signals. In many cases, nsinc.d
and nsinc.z
can give similar results. However, if the user's proximity of interest is larger than half of the largest inter-point distances, then nsinc.d
is suggested.
nsinc.z
returns colocalization index values at each separate proximity size r, and the average colocalization index across all r's, the data that the colocalization index is calculated from, the study region, i.e., the carrying box, the original and normalized proportions of each type of signals in an r neighborhodd of all (base) signals, the r series, and some summary information:
method |
"nsinc.z" |
input.data.summary |
a list containing the number of membership levels and the signal counts in each channel or membership of the input data. |
post.data.summary |
a list showing the number of membership levels and signal counts in each channel of the data after removal of signals located outside the specified box by the user. If there is no signals excluded, then |
r.summary |
a data frame listing the |
strata |
a list showing the default setting of strata or the specified strata by the user. It also presents the base membership used in the function if |
edge.effect |
a data frame containing a logical value indicating whether edge effect is corrected or not. |
index.all |
a data frame showing the colocalization index of z-type at each r. |
index |
the averaged colocalization index of z-type across all r's. |
post.data |
a data frame representing the data after removal of signals located outside the specified box by the user. If there is no signal excluded, then |
study.region |
the carrying box with the size of buffer width in each dimension. |
P.all |
the data frame showing all original and normalized proportions of each type of signals in an r-neighborhood around every (base) signal. Rows are (base) signals and columns are all memberships and r's. |
r |
the r series for which the colocalization indices are calculated. |
Xueyan Liu, Jiahui Xu, Cheng Cheng, Hui Zhang.
Liu, X., Xu, J., Guy C., Romero E., Green D., Cheng, C., Zhang, H. (2019). Unbiased and Robust Analysis of Co-localization in Super-resolution Images. Manuscript submitted for publication.
## a simulated 2D example data. set.seed(1234) x <- runif(300, min = -1, max = 1) y <- runif(300, min = -1, max = 1) red <- data.frame(x,y, color = "red") x <- runif(50, min = -1, max = 1) y <- runif(50, min = -1, max = 1) green <- data.frame(x,y, color = "green") mydata <- rbind(red,green) plot(mydata$x,mydata$y,col = mydata$color) mydata.results <- nsinc.z(data = mydata, membership = "color", dim = 2, r.model = "other", r.min = 0.01, r.max = 0.5, r.count = 5, r.adjust = 0) mydata.results$index.all mydata.results$index ## a simulated 3D example data. data("twolines") library("rgl") plot3d(twolines[,c("x","y","z")], type='s', size=0.7, col = twolines$membership) aspect3d("iso") twolines.results <- nsinc.z(data = twolines, membership = "membership", dim = 3, r.model = "full") twolines.results$index
## a simulated 2D example data. set.seed(1234) x <- runif(300, min = -1, max = 1) y <- runif(300, min = -1, max = 1) red <- data.frame(x,y, color = "red") x <- runif(50, min = -1, max = 1) y <- runif(50, min = -1, max = 1) green <- data.frame(x,y, color = "green") mydata <- rbind(red,green) plot(mydata$x,mydata$y,col = mydata$color) mydata.results <- nsinc.z(data = mydata, membership = "color", dim = 2, r.model = "other", r.min = 0.01, r.max = 0.5, r.count = 5, r.adjust = 0) mydata.results$index.all mydata.results$index ## a simulated 3D example data. data("twolines") library("rgl") plot3d(twolines[,c("x","y","z")], type='s', size=0.7, col = twolines$membership) aspect3d("iso") twolines.results <- nsinc.z(data = twolines, membership = "membership", dim = 3, r.model = "full") twolines.results$index
This function is used to make scatter plots for signal proportions based on the results returned from the nsinc.d
or nsinc.z
function.
## S3 method for class 'colocal' plot(x, ...)
## S3 method for class 'colocal' plot(x, ...)
x |
an object of class |
... |
further arguments to be passed from or to other methods. |
The function currently works for results from nsinc.d
or nsinc.z
with bi-direction colocalization for dual-color images. At each proximity size r, the function makes two panels of scatter plots for signal proportions at all signals before and after d-type or z-type normalizations. Each signal in the original image contributes a point in the scatter plots whose x coordinate is the proportion of signals in one channel and y coordinate is the other channel. The scatter plots have the same color codes as signals in the original image. If the returned results contain colocalization results at multiple r's, then the scatter plots at each r are generated.
plot.colocal
returns a list of plots which summarize the results returned from the nsinc.d
or nsinc.z
function.
Xueyan Liu, Jiahui Xu, Cheng Cheng, Hui Zhang.
Liu, X., Xu, J., Guy C., Romero E., Green D., Cheng, C., Zhang, H. (2019). Unbiased and Robust Analysis of Co-localization in Super-resolution Images. Manuscript submitted for publication.
## a simulated 3D example data. data("twolines") twolines.results <- nsinc.d(data = twolines, membership = "membership", dim = 3, r.model = "r.med") ##plot(twolines.results)
## a simulated 3D example data. data("twolines") twolines.results <- nsinc.d(data = twolines, membership = "membership", dim = 3, r.model = "r.med") ##plot(twolines.results)
This function is used to summarize the results returned from the nsinc.d
or nsinc.z
function.
## S3 method for class 'colocal' summary(object, ...)
## S3 method for class 'colocal' summary(object, ...)
object |
an object of class |
... |
further arguments to be passed from or to other methods. |
The results successfully returned from nsinc.d
or nsinc.z
functions give a list of length 12 encompassing the summarized information of the calculation of colocalization index and the detailed quantities used to calculate the index.
First the summary prints the strategic parameters for calculation of colocalization index, such as, the method, the strata, the edge effect, dimension, study region, membership levels and number of the observed signals in each channel.
The summary also prints the summarized information of proximity sizes, i.e., r, including the r model, the r range, the length of r series, etc.
Then the separate index results are listed at each r. The average colocalization index for the whole image is given at last.
summary.colocal
does not return values. It only prints summarized results returned from nsinc.d
or nsinc.z
functions.
Xueyan Liu, Jiahui Xu, Cheng Cheng, Hui Zhang.
Liu, X., Xu, J., Guy C., Romero E., Green D., Cheng, C., Zhang, H. (2019). Unbiased and Robust Analysis of Co-localization in Super-resolution Images. Manuscript submitted for publication.
## a simulated 3D example data. data("twolines") twolines.results <- nsinc.d(data = twolines, membership = "membership", dim = 3, r.model = "r.med") summary(twolines.results)
## a simulated 3D example data. data("twolines") twolines.results <- nsinc.d(data = twolines, membership = "membership", dim = 3, r.model = "r.med") summary(twolines.results)
The test data is a simulated 3D dataset of 2-colored lines, i.e., red, green, whose pivots intersect at the origin in the unit box [-1, 1] x [-1, 1] x [-1, 1].
data("twolines")
data("twolines")
A data frame with the precise x,y,z coordinates of 426 signal points with marked colors for their memberships. The x,y,z coordinates are within the interval [-1,1].
x
the x coordinate
y
the y coordinate
z
the z coordinate
membership
a factor with levels red
and green
The pivots of the red and green lines are respectively, (t,0,0), (t*cos(atan(5)), t*sin(atan(5)), 0). The number of points along each pivot within the unit box is Poisson(200). The t values are generated by the uniform distribution. The perturbations for locations of all signals are generated independently in the orthogonal plane away from the pivot with zero mean and SD = 0.1 for the displacements together with the uniformly distributed random rotations.
From Xueyan Liu, Jiahui Xu, Cheng Cheng, Hui Zhang.
N/A
data("twolines") library(rgl) plot3d(twolines[,c("x","y","z")], type = 's', size = 0.8, col = twolines$membership) aspect3d("iso")
data("twolines") library(rgl) plot3d(twolines[,c("x","y","z")], type = 's', size = 0.8, col = twolines$membership) aspect3d("iso")