首页 文章

时间标准化R中的跳跃力变量

提问于
浏览
0

我有一个数据集,其中包含一名运动员提供的两次垂直跳跃的垂直地面反作用力 . 这是一个连续变量 . 我还有一个专栏给出了运动员的位移,这也是一个连续的变量 . 对于两次跳跃,数据以500Hz采样,但跳跃#1比跳转#2花费更多时间执行,因此它具有更多行数 .

我想将每次跳跃的位移标准化,从总位移的0到100%的比例,以使两个跳跃的力变量相等 . 然后我想计算跳跃中平均力与位移曲线的平均值 .

由于数据集很长,我已经包含了一个缩短的示例,说明了数据当前是如何存在的,以及我希望它最终看起来如何 . 我希望有人能够提供一个很好的方法来规范化位移,范围从0到100%,并确保每次跳转的行数相同 .

注意:在下面的代码中,我选择表示10 Hz的采样频率,只是为了说明如何以简单的方式设置数据,以便我可以就我的方法获得一些建议 .

Current raw data structure:

Jump_Number     Displacement    Force    Time
     1               0           800       0
     1             -0.10         700       0.1
     1             -0.29         500       0.2
     1             -0.40         200       0.3
     1             -0.45         100       0.4
     1             -0.50         500       0.5
     1             -0.30         800       0.6
     1             -0.10         1200      0.7
     1             -0.05         1300      0.8
     1              0.05         1250      0.9
     2               0           800       0.0
     2             -0.10         678       0.1
     2             -0.29         499       0.2
     2             -0.40         178       0.3
     2             -0.45         90        0.4
     2             -0.50         600       0.5
     2             -0.40         810       0.6
     2             -0.35         999       0.7
     2             -0.29         1135      0.8
     2             -0.10         1250      0.9
     2             -0.05         1401      1.0
     2              0.05         1345      1.1

Desired normalized data structure:

Jump_Number     Normalized_Displacement_(%)  Force    
     1                     0                    800       
     1                    10                    700       
     1                    20                    500       
     1                    30                    200       
     1                    40                    100       
     1                    50                    500       
     1                    60                    800       
     1                    70                    1200      
     1                    80                    1300      
     1                    90                    1289
     1                   100                    1250     
     2                    0                     800       
     2                   10                     678      
     2                   20                     499       
     2                   30                     178       
     2                   40                     90        
     2                   50                     600       
     2                   60                     810       
     2                   70                     999       
     2                   80                     1135      
     2                   90                     1250      
     2                  100                     1345

1 回答

  • 0

    我将假设您并不真正期望对应于“标准化位移”的力等于原始位移的力 . 有了这个假设,您可以使用下面的脚本生成所需的数据 .

    require(ggplot2)
    
    # Read the data
    jump_names = c("Jump_Number", "Displacement", "Force", "Time")
    jump_data = transpose(data.frame(
         c(1, 0, 800, 0),
         c(1, -0.10, 700, 0.1),
         c(1, -0.29, 500, 0.2),
         c(1, -0.40, 200, 0.3),
         c(1, -0.45, 100, 0.4),
         c(1, -0.50, 500, 0.5),
         c(1, -0.30, 800, 0.6),
         c(1, -0.10, 1200, 0.7),
         c(1, -0.05, 1300, 0.8),
         c(1, 0.05, 1250, 0.9),
         c(2, 0, 800, 0.0),
         c(2, -0.10, 678, 0.1),
         c(2, -0.29, 499, 0.2),
         c(2, -0.40, 178, 0.3),
         c(2, -0.45, 90, 0.4),
         c(2, -0.50, 600, 0.5),
         c(2, -0.40, 810, 0.6),
         c(2, -0.35, 999, 0.7),
         c(2, -0.29, 1135, 0.8),
         c(2, -0.10, 1250, 0.9),
         c(2, -0.05, 1401, 1.0),
         c(2, 0.05, 1345, 1.1)))
    names(jump_data) =  jump_names
    jump_data$Jump_Number = as.factor(jump_data$Jump_Number)
    
    # Compute percent displacement
    jump_data$Total_Displacement = ave(abs(jump_data$Displacement), jump_data$Jump_Number, FUN = cumsum)
    jump_data$Max_Displacement = ave(abs(jump_data$Total_Displacement), jump_data$Jump_Number, FUN = max)
    jump_data$Percent_Displacement = jump_data$Total_Displacement/jump_data$Max_Displacement*100
    
    # Split the data
    jump_data_split = split(jump_data, jump_data$Jump_Number)
    
    # Apply interpolation and the combine
    interp_data = data.frame()
    for (ii in 1:length(jump_data_split)) {
      linear_interp = data.frame(approx(jump_data_split[[ii]]$Percent_Displacement, 
                    jump_data_split[[ii]]$Force, 
                    xout = seq(0, 100, by = 10), 
                    method = "linear"))
      linear_interp$Jump_Number = paste0(ii, "interp")
      interp_data = rbind(interp_data, linear_interp)
    }
    interp_data$Jump_Number = as.factor(interp_data$Jump_Number)
    names(interp_data) = c("Percent_Displacement", "Force", "Jump_Number")
    
    # Plots
    plt = ggplot(jump_data,
                 aes(x = Time, y = -Displacement, 
                     color = Jump_Number, group = Jump_Number)) +
          geom_path() + 
          theme_bw()
    print(plt)
    dev.copy(png, "disp_time.png")
    dev.off()
    
    dev.new()
    plt0 = ggplot(jump_data,
                 aes(x = Time, y = Total_Displacement, 
                     color = Jump_Number, group = Jump_Number)) +
          geom_path() + 
          theme_bw()
    print(plt0)
    dev.copy(png, "tot_disp_time.png")
    dev.off()
    
    dev.new()
    plt1 = ggplot(jump_data,
                 aes(x = Time, y = Force, 
                     color = Jump_Number, group = Jump_Number)) +
          geom_path() + 
          theme_bw()
    print(plt1)
    dev.copy(png, "force_time.png")
    dev.off()
    
    dev.new()
    plt2 = ggplot()+
             geom_path(data = jump_data, aes(x = Percent_Displacement, y = Force, 
                     color = Jump_Number, group = Jump_Number)) +
             geom_path(data = interp_data, aes(x = Percent_Displacement, y = Force, 
                     color = Jump_Number, group = Jump_Number)) +
          theme_bw()
    print(plt2)
    dev.copy(png, "force_percent_disp.png")
    dev.off()
    
    names(interp_data) = c("Normalized_Displacement_(%)", "Force", "Jump_Number")
    print(interp_data)
    

    脚本生成的一个图是:

    percent_displacement_time

相关问题