경기가 진행되는 특정 경기장을 나타내는 x 개의 열이있는 교육 세트가 있습니다. 적어도 경기장 중 하나에서 경기가 발생해야하기 때문에 기둥이 훈련 세트에 선형으로 종속되어 있음은 분명합니다.glm에 선형 종속 함수 포함
그러나 문제는 내가 테스트 데이터를 전달하면 훈련 데이터에 표시되지 않은 경기장이 포함될 수 있다는 것입니다. 따라서 모든 경기장 계수의 평균이 0이되도록 Rxm을 훈련 할 때 x 열을 모두 포함하고자합니다. 그런 다음 새로운 경기장이 보일 경우 모든 경기장 계수의 평균이 주어질 것입니다.
문제는 R glm 함수가 훈련 세트에서 선형 종속 열을 감지하여 계수 중 하나를 NA로 설정하여 그 나머지를 선형 적으로 독립적으로 만드는 것입니다. 어떻게해야합니까 :
R은 glm 함수에서 내 열 중 하나에 대한 NA 계수를 삽입하고 모든 경기장 계수의 합이 0으로되도록 만드시겠습니까?
모든 수준에 대한 계수를 포함하는 방법에 대한 질문에 대해서는 일부 예제 코드
# Past observations
outcome = c(1 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,1 ,0 ,1 )
skill = c(0.1,0.5,0.6,0.3,0.1,0.3,0.9,0.6,0.5,0.1,0.4)
stadium_1 = c(1 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 )
stadium_2 = c(0 ,0 ,1 ,1 ,1 ,1 ,1 ,0 ,0 ,0 ,0 )
stadium_3 = c(0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,1 )
train_glm_data = data.frame(outcome, skill, stadium_1, stadium_2, stadium_3)
LR = glm(outcome ~ . - outcome, data = train_glm_data, family=binomial(link='logit'))
print(predict(LR, type = 'response'))
# New observations (for a new stadium we have not seen before)
skill = c(0.1)
stadium_1 = c(0 )
stadium_2 = c(0 )
stadium_3 = c(0 )
test_glm_data = data.frame(outcome, skill, stadium_1, stadium_2, stadium_3)
print(predict(LR, test_glm_data, type = 'response'))
# Note that in this case, the observation is simply the same as if we had observed stadium_3
# Instead I would like it to be an average of all the known stadiums coefficients
# If they all sum to 0 this is essentially already done for me
# However if not then the stadium_3 coefficient is buried somewhere in the intercept term
피팅중인'glm' 모델은 무엇입니까? 최소한의 재현 가능한 예제를 제공하면 도움이됩니다. –
마지막 계수에 대한 [선형 회귀 분석 "NA"추정치]의 가능한 복제본 (http://stackoverflow.com/questions/7337761/linear-regression-na-estimate-just-for-last-coefficient) –