将自定义函数映射到嵌套的小对象上

时间:2019-10-12 22:01:24

标签: r

我有一个看起来像这样的数据集:

LogisticFun <- function(Formula, data, train_ind, test_ind){
  train_data =  data[1:train_ind, ] %>%
    select("Y", matches("X\\d+"))
  Logisticfit <- glm(Formula, data = train_data)

  test_data = data[(nrow(data) - test_ind):nrow(data),] %>%
    select("Y", matches("X\\d+"))
  Predictions <- predict(Logisticfit, newdata = test_data, type = 'response')
  return(Predictions)
}

LogisticFun(Formula = formula(reformulate(paste0("X", seq(5:ncol(df))), "Y"))
            , data = df, train_ind = 100, test_ind = 100)

我想按符号分组并应用逻辑模型,我有以下功能(适用于整个数据集)

id

我想做的是嵌套数据并将logistic函数应用于每个df %>% group_by(.id) %>% nest() %>% Apply function... ,如下所示:

df <- structure(list(Y = c(1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 
1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 
1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 
1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 
1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 
0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 
1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 
1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 
0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 
1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 
1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 
0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 
1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 
0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 
0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0), .id = c("AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL", 
"AAPL", "AAPL", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "GOOG", 
"GOOG", "GOOG", "GOOG", "GOOG", "GOOG", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", 
"MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT", "MSFT"
), date = structure(c(17366, 17367, 17368, 17371, 17372, 17373, 
17374, 17375, 17378, 17379, 17380, 17381, 17382, 17385, 17386, 
17387, 17388, 17389, 17392, 17393, 17394, 17395, 17396, 17399, 
17400, 17401, 17402, 17403, 17406, 17407, 17408, 17409, 17410, 
17414, 17415, 17416, 17417, 17420, 17421, 17422, 17423, 17424, 
17427, 17428, 17429, 17430, 17431, 17434, 17435, 17436, 17437, 
17438, 17441, 17442, 17443, 17444, 17445, 17448, 17449, 17450, 
17451, 17452, 17455, 17456, 17457, 17458, 17459, 17462, 17463, 
17464, 17465, 17466, 17469, 17470, 17471, 17472, 17473, 17476, 
17477, 17478, 17479, 17480, 17483, 17484, 17485, 17486, 17487, 
17490, 17491, 17492, 17494, 17497, 17498, 17499, 17500, 17501, 
17504, 17505, 17506, 17507, 17508, 17511, 17512, 17513, 17514, 
17515, 17518, 17519, 17520, 17521, 17522, 17526, 17527, 17528, 
17529, 17366, 17367, 17368, 17371, 17372, 17373, 17374, 17375, 
17378, 17379, 17380, 17381, 17382, 17385, 17386, 17387, 17388, 
17389, 17392, 17393, 17394, 17395, 17396, 17399, 17400, 17401, 
17402, 17403, 17406, 17407, 17408, 17409, 17410, 17414, 17415, 
17416, 17417, 17420, 17421, 17422, 17423, 17424, 17427, 17428, 
17429, 17430, 17431, 17434, 17435, 17436, 17437, 17438, 17441, 
17442, 17443, 17444, 17445, 17448, 17449, 17450, 17451, 17452, 
17455, 17456, 17457, 17458, 17459, 17462, 17463, 17464, 17465, 
17466, 17469, 17470, 17471, 17472, 17473, 17476, 17477, 17478, 
17479, 17480, 17483, 17484, 17485, 17486, 17487, 17490, 17491, 
17492, 17494, 17497, 17498, 17499, 17500, 17501, 17504, 17505, 
17506, 17507, 17508, 17511, 17512, 17513, 17514, 17515, 17518, 
17519, 17520, 17521, 17522, 17526, 17527, 17528, 17529, 17366, 
17367, 17368, 17371, 17372, 17373, 17374, 17375, 17378, 17379, 
17380, 17381, 17382, 17385, 17386, 17387, 17388, 17389, 17392, 
17393, 17394, 17395, 17396, 17399, 17400, 17401, 17402, 17403, 
17406, 17407, 17408, 17409, 17410, 17414, 17415, 17416, 17417, 
17420, 17421, 17422, 17423, 17424, 17427, 17428, 17429, 17430, 
17431, 17434, 17435, 17436, 17437, 17438, 17441, 17442, 17443, 
17444, 17445, 17448, 17449, 17450, 17451, 17452, 17455, 17456, 
17457, 17458, 17459, 17462, 17463, 17464, 17465, 17466, 17469, 
17470, 17471, 17472, 17473, 17476, 17477, 17478, 17479, 17480, 
17483, 17484, 17485, 17486, 17487, 17490, 17491, 17492, 17494, 
17497, 17498, 17499, 17500, 17501, 17504, 17505, 17506, 17507, 
17508, 17511, 17512, 17513, 17514, 17515, 17518, 17519, 17520, 
17521, 17522, 17526, 17527, 17528, 17529), class = "Date"), Adjusted = c(145.9, 
145.3, 145.2, 147, 147.6, 148.3, 145.5, 144.5, 143.7, 145, 151.8, 
150.3, 151.1, 153.5, 154.7, 155.6, 150.7, 152.8, 155.1, 156.8, 
156.1, 153.1, 152.8, 152.5, 155, 155.2, 154.5, 155.1, 156.6, 
158, 158.5, 159.1, 159.1, 157.2, 157.1, 156.4, 153.9, 156.7, 
156, 154.9, 153.5, 155.1, 153.9, 154, 151.4, 148.8, 147.3, 146, 
148.6, 149.6, 148.7, 149.5, 149.2, 149.9, 148.9, 150.7, 150.6, 
151.2, 151.2, 151.9, 151.3, 152.3, 155.1, 155.7, 155, 151.3, 
151.6, 151.5, 152.4, 151.7, 152.7, 158.2, 161.7, 164, 161.9, 
163.1, 167.3, 169, 169.6, 171, 170.6, 170, 169.4, 166.8, 164.6, 
166.6, 165.6, 165.5, 168.6, 170.3, 170.3, 169.5, 168.5, 165, 
167.3, 166.5, 165.3, 165.2, 164.5, 164.8, 164.9, 168.1, 167.2, 
167.7, 167.7, 169.4, 171.8, 169.9, 169.7, 170.4, 170.4, 166.1, 
166.1, 166.6, 164.8, 970.9, 968.2, 972.9, 980.3, 950.7, 947.8, 
934.1, 941.5, 930.5, 930.8, 930.4, 923.7, 928, 929.4, 926.8, 
922.9, 907.2, 914.4, 922.7, 922.2, 927, 911, 910.7, 906.7, 924.7, 
927, 921.3, 915.9, 913.8, 921.3, 929.6, 939.3, 937.3, 928.5, 
927.8, 936, 926.5, 929.1, 932.1, 935.1, 925.1, 920.3, 915, 921.8, 
931.6, 932.5, 928.5, 921, 924.9, 944.5, 949.5, 959.1, 953.3, 
957.8, 951.7, 970, 978.9, 977, 972.6, 989.2, 987.8, 989.7, 992, 
992.2, 992.8, 984.5, 988.2, 968.5, 970.5, 973.3, 972.6, 1019.3, 
1017.1, 1016.6, 1025.5, 1025.6, 1032.5, 1025.9, 1033.3, 1039.8, 
1031.3, 1028.1, 1025.8, 1026, 1020.9, 1032.5, 1019.1, 1018.4, 
1034.5, 1036, 1040.6, 1054.2, 1047.4, 1021.7, 1021.4, 1010.2, 
998.7, 1005.2, 1018.4, 1030.9, 1037.1, 1041.1, 1040.5, 1040.6, 
1049.2, 1064.2, 1077.1, 1070.7, 1064.9, 1063.6, 1060.1, 1056.7, 
1049.4, 1048.1, 1046.4, 71.1, 71.4, 71, 70.8, 71.4, 71.2, 70.4, 
70.3, 69.9, 69.8, 69.5, 69.4, 69.9, 69.6, 70, 69.7, 68.7, 69.7, 
70.8, 70.8, 71.2, 70, 70.1, 69.8, 70.8, 70.3, 70.3, 70.4, 70.4, 
70.6, 71.6, 72.3, 71.5, 71.2, 71, 71.9, 71.5, 72.3, 72.2, 72.7, 
72.3, 72.8, 72.7, 73, 72.5, 71.8, 72, 70.8, 70.8, 71.4, 71.4, 
72, 72.2, 71.8, 72.2, 73.5, 73.5, 73.8, 73.8, 73.9, 74.6, 74.9, 
75.1, 75, 75.1, 75.3, 76.2, 76.2, 76.3, 76, 76.2, 81.1, 81.1, 
80.4, 80.4, 81.3, 81.4, 81.7, 81.5, 81.8, 81.3, 81.1, 81.2, 81.3, 
80.7, 80.9, 80.1, 80.2, 81.4, 80.8, 80.9, 81.5, 82.5, 81, 81.8, 
81.9, 78.8, 79.3, 80.5, 80.2, 81.8, 82.8, 83.2, 83, 82.3, 84.4, 
84, 83.4, 83.1, 83.1, 83.1, 83, 83.3, 83.3, 83.1), X1 = c(-0.2, 
-0.1, 0.1, 0.2, 0.4, 0.5, 0.6, 0.7, 0.7, 0.6, 0.7, 0.7, 0.7, 
0.8, 0.8, 0.9, 0.8, 0.7, 0.8, 0.9, 1.1, 1.2, 1, 1, 0.9, 0.8, 
0.7, 0.5, 0.6, 0.6, 0.5, 0.4, 0.3, 0.2, 0.2, 0.1, 0.1, 0, 0, 
0, -0.1, -0.2, -0.4, -0.6, -0.7, -0.9, -1.1, -1.3, -1.4, -1.6, 
-1.7, -1.8, -1.9, -2, -2, -2, -1.9, -1.7, -1.5, -1.2, -1.1, -0.9, 
-0.7, -0.5, -0.3, -0.2, -0.1, 0, 0.1, 0.1, 0.1, 0.2, 0.3, 0.4, 
0.4, 0.5, 0.6, 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0.1, 0.1, 0.3, 0.1, -0.1, -0.1, -0.2, -0.6, -0.7, -1.2, 
-0.7, -0.4, -0.2, -0.6, -0.5, -0.4, -0.9, -0.7, -0.9, -0.6, -0.5, 
0.4, 0.4, 0.2, 0.4, 0.5, 0.6, -0.1, -0.1, -0.6, -0.7, 1.8, 2, 
1.7, 2.1, 0.8, 0.3, -0.1, -0.4, -0.8, -1.1, -1, -1.6, -1.7, -1.6, 
-1.8, -2.2, -1.7, -1.4, -0.7, -0.9, -0.4, -0.9, -0.9, -0.8, -0.4, 
-0.4, -0.5, -0.5, -0.1, 0, 0, 0.3, 0.1, 0.3, 0.3, 0.7, -0.2, 
-0.2, 0.1, 0.4, 0.1, -0.3, -0.8, -0.9, -0.5, -0.1, -0.3, -0.8, 
-0.3, 0.2, 0.3, 0.5, 0.6, 1, 0.9, 1.3, 1.3, 1.2, 1.2, 2, 1.8, 
1.2, 1.1, 0.8, 1, 0.6, 0.9, -0.3, -0.6, -0.4, -0.3, 0.7, 0.7, 
0.6, 0.8, 0.8, 1, 1.1, 1.2, 2.1, 1.7, 1.5, 1.5, -0.1, -0.2, 0.2, 
-0.5, -0.5, -0.2, 0.1, 0, 0.2, 0.3, -0.5, -0.4, -0.8, -1, -1.2, 
-0.3, 0.1, -0.2, -0.1, -0.3, -0.7, -0.2, 1.1, 1.6, 1.7, 1.9, 
1.6, 1.1, 0.6, 0.1, 0, -0.1, 1.5, 2, 1.4, 1.6, 1.4, 1.2, 0.8, 
0.2, -0.2, -0.7, -1.1, -1.1, -1.1, -1.4, -1, -1.1, -1.8, -1.2, 
-0.4, -0.3, 0, -0.5, -0.3, -0.4, -0.2, -0.3, -0.5, -0.3, 0.2, 
-0.2, -0.2, 0.1, -0.5, -0.1, -0.2, 0.4, -0.2, 0.3, 0.3, 0.4, 
0.2, 0.4, -0.1, -0.3, -0.2, -0.3, -0.2, -1.1, -0.9, -1, -0.9, 
-0.9, -0.7, -1, -0.8, -0.4, -0.1, 0.3, 0.2, 0.8, 1.1, 1, 1, 0.7, 
0.7, 1, 1.2, 0.6, 0.6, 0.4, 0.5, 2.6, 2.3, 1.9, 1.8, 2.2, 2.2, 
2.2, 1.8, 1.9, 1.7, 1.7, 1.6, -0.5, -0.8, -0.4, -0.7, -1.1, -0.6, 
-1, -0.8, -0.7, -0.1, -0.6, -0.3, -0.3, -1.4, -1.3, -0.4, -0.6, 
-0.4, 0.3, 0.4, 0.1, -0.7, 0.9, 0.4, 0.1, 1.3, 1.1, 0.6, 0.7, 
0.1, -0.4, -0.6)), class = "data.frame", row.names = c(NA, -345L
))

如何映射每个“ .id”并应用该功能。

数据:

.clicked

1 个答案:

答案 0 :(得分:1)

如果公式相同,则我们在map的'数据'上循环,并应用LogisticFun并指定为data的{​​{1}}并创建一个{ .x中的{1}}列(“新”)

list