2016-07-05 3 views
1

Velocity (숫자), Height (숫자), Gender (범주 형)의 데이터 프레임 PlotData_df이 있습니다.그룹화 된 데이터에 대한 회귀 방정식을 내보내는 방법은 무엇입니까?

c <- lm(Height ~ Velocity, data = PlotData_df) 

summary(c) 
#    Estimate Std. Error t value Pr(>|t|) 
# (Intercept) 4.1283  1.0822 3.815 0.00513 ** 
# Velocity  -0.3240  0.2854 -1.135 0.28915 
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
# Residual standard error: 0.4389 on 8 degrees of freedom 
# Multiple R-squared: 0.1387, Adjusted R-squared: 0.03108 
# F-statistic: 1.289 on 1 and 8 DF, p-value: 0.2892 

a <- signif(coef(c)[1], digits = 2) 
b <- signif(coef(c)[2], digits = 2) 
Regression <- paste0("Velocity = ",b," * Height + ",a) 
print(Regression) 
# [1] "Velocity = -0.32 * Height + 4.13" 

가 어떻게이 (성별은 남성 또는 여성인지에 따라)이 회귀 방정식을 표시하기 위해 확장 할 수

 Velocity Height Gender 
1  4.1 3.0 Male 
2  3.1 4.0 Female 
3  3.9 2.4 Female 
4  4.6 2.8 Male 
5  4.1 3.3 Female 
6  3.1 3.2 Female 
7  3.7 3.0 Male 
8  3.6 2.4 Male 
9  3.2 2.7 Female 
10  4.2 2.5 Male 

는 내가이 완료 데이터를 회귀 방정식을 제공하기 위해 다음과 같은 사용?

답변

1

성별이 남성 또는 여성인지에 따라 두 회귀 방정식을 표시하려면 어떻게해야합니까?

먼저 HeightGender 사이의 상호 작용이있는 선형 모델이 필요합니다. 시도 :

fit <- lm(formula = Velocity ~ Height * Gender, data = PlotData_df) 

을 그럼 당신은 장착 회귀 기능/방정식을 표시하려는 경우. Male에 하나, Female에 하나, 두 개의 방정식을 사용해야합니다. 계수/숫자를 연결하기로 결정 했으므로 다른 방법은 없습니다. 다음은이를 가져 오는 방법을 보여줍니다. 당신이 불분명 한 경우

## formatted coefficients 
beta <- signif(fit$coef, digits = 2) 
# (Intercept) Height GenderMale Height:GenderMale 
#  4.42 -0.30  -1.01    0.54 

## equation for Female: 
eqn.female <- paste0("Velocity = ", beta[2], " * Height + ", beta[1]) 
# [1] "Velocity = -0.30 * Height + 4.42" 

## equation for Male: 
eqn.male <- paste0("Velocity = ", beta[2] + beta[4], " * Height + ", beta[1] + beta[3]) 
# [1] "Velocity = 0.24 * Height + 3.41" 

이유

  • 그룹 Male에 대한 절편이 beta[1] + beta[3]이다;
  • Male의 기울기가 beta[2] + beta[4]이다,

당신은 ANOVA 및 요인 변수 대비 처리 주위를 읽을 필요가있다. This question on Cross Validated: How to interpret dummy and ratio variable interactions in R은 너와 매우 비슷한 설정을 가지고 있습니다. 나는 계수에 대한 해석에 대해 아주 간단한 답을 만들었습니다. 그래서 당신이 볼 수 있었을 것입니다.

관련 문제