如何使用circular包的conversion.circular函数缩放中心化圆形分布
conversion.circular First, let's break down how to use the conversion.circular function from the circular package to process your circular data. Your dataset has missing values (NA) and appears to be in geographic degrees (0-360, clockwise rotation), so we'll need to account for both of these details.
Step 1: Prep Your Data
First, you need to handle the NA values—most functions in the circular package don't handle missing data gracefully. Use na.omit() to clean your dataset:
library(circular) # Your existing circular object x <- structure(c(44, 95, 88, NA, 317, 16, NA, NA, 85, NA, 31, 14, 323, 336, 345, 338, 10, 3, 342, 325, 30, 311, 359, 335, 331, 4, 347, 9, 9, 33, 335, 345, 355, 346, 18, 9, 341, 24, 352, 343, 3, 22, NA, 356, 14, 5, 8, NA, 352, 36, NA, 312, 352, 8, 351, 338, 341, 316, 357, 331, 326, 8, 347, 342, 315, 336, 9, 355, 0, 227, 14, 292, NA, 342, 352, 351, 1, 339, 358, 341, 1, 22, 20, 1, 285, 357, 279, 13, 25, 16, 353, 348, 2, 354, 357, 32, 7), class = "circular", units = "degrees", template = "geographics", modulo = "2pi", zero = 0, rotation = "clockwise") # Clean missing values x_clean <- na.omit(x)
Step 2: Centering Your Circular Data
Centering adjusts your data so that the mean direction of the dataset aligns with a reference direction (default is 0 degrees, which in your geographic template is North). Use type = "center" in conversion.circular:
# Center the data (mean direction becomes 0 degrees) x_centered <- conversion.circular(x_clean, type = "center", units = "degrees")
This works by subtracting the circular mean of your original data from each observation, wrapping angles appropriately to stay within the 0-360 degree range.
Step 3: Scaling Your Circular Data
Scaling standardizes the spread of your circular data. By default, it scales the data so that the circular standard deviation becomes 1. Use type = "scale" and specify scale = 1 (you can adjust this value if you need a different scaling factor):
# Scale the data to have a circular standard deviation of 1 x_scaled <- conversion.circular(x_clean, type = "scale", units = "degrees", scale = 1)
This divides each observation by the circular standard deviation of the original dataset.
Step 4: Combine Centering and Scaling
You can do both operations in a single call by passing a vector to type:
# Center first, then scale x_processed <- conversion.circular(x_clean, type = c("center", "scale"), units = "degrees", scale = 1)
Alternatively, use type = "cscale" which is a shorthand for "center then scale".
Key Notes
- Units Match: Always ensure the
unitsparameter matches your original data (you're using degrees, so stick with"degrees"). - NA Handling: Never skip cleaning
NAvalues—this will cause errors or invalid results inconversion.circular. - Preserve Attributes: The function retains your circular object's template (geographic), rotation (clockwise), and other properties, so you don't have to redefine them.
To verify the results, use summary(x_processed) to check the new mean direction (should be 0 degrees) and circular standard deviation (should be 1 if you used scale = 1).
内容的提问来源于stack exchange,提问作者Kuba Krukar

