2016-10-12 6 views
-1

私の用語のいくつかは因子変数(季節、月、祝日、平日、weathersit)である、相互作用項を含む以下のような多重線形回帰を持っています複数の線形回帰 - 変換された2次変数とファクタ変数の相互作用

regwithint=lm(casual~season:temp+season:month+year:temp+ 
      month:temp+holiday:temp+weekday:hum+season+ 
      month+holiday+weekday+weathersit+temp+windspeed 
      ,data=training) 

しかし、変数tempとwindspeedは(temp^3)と(windspeed^2)に変換されました。平日 一時は一時^ 3や曜日が要因変数である:相互作用項を見ると

、私は一時の間の相互作用を持っています。

私は(3^TEMP)を、ほとんどの場合のために、私はを使用する必要があります知っているが、それは因子変数とペアになっているという事実は、私がポリ(一時、3、生= T)を使用する必要がありますどういう意味代わりに?

ありがとうございます。

+0

この質問は奇妙なことです。 –

答えて

0

まずは、I()が要因変数の相互作用で正常に動作することを確立してみましょう:

data(iris) 
reg <- lm(Sepal.Length~Species:I(Petal.Length^2), data=iris) 
summary(reg) 
Call: 
lm(formula = Sepal.Length ~ Species:I(Petal.Length^2), data = iris) 

Residuals: 
    Min  1Q Median  3Q  Max 
-0.87875 -0.22363 -0.00197 0.21664 1.06243 

Coefficients: 
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)       4.245539 0.133172 31.880 < 2e-16 *** 
Speciessetosa:I(Petal.Length^2)  0.341688 0.062196 5.494 1.7e-07 *** 
Speciesversicolor:I(Petal.Length^2) 0.092381 0.007413 12.462 < 2e-16 *** 
Speciesvirginica:I(Petal.Length^2) 0.075714 0.004388 17.253 < 2e-16 *** 
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.3431 on 146 degrees of freedom 
Multiple R-squared: 0.8318, Adjusted R-squared: 0.8284 
F-statistic: 240.7 on 3 and 146 DF, p-value: < 2.2e-16 

今、あなたの関数があまりにも動作するかどうかを見てみましょう:

data(iris) 
reg <- lm(Sepal.Length~Species: poly(Petal.Length,2,raw=T), data=iris) 
summary(reg) 

それがありません(それには低次の用語も必要であるという点で異なります):

Call: 
lm(formula = Sepal.Length ~ Species:poly(Petal.Length, 2, raw = T), 
    data = iris) 

Residuals: 
    Min  1Q Median  3Q  Max 
-0.73849 -0.22814 -0.01978 0.24177 0.98833 

Coefficients: 
                Estimate Std. Error t value Pr(>|t|) 
(Intercept)          1.79002 1.58957 1.126 0.2620 
Speciessetosa:poly(Petal.Length, 2, raw = T)1  3.87221 2.16771 1.786 0.0762 . 
Speciesversicolor:poly(Petal.Length, 2, raw = T)1 1.13016 0.78109 1.447 0.1501 
Speciesvirginica:poly(Petal.Length, 2, raw = T)1 0.74216 0.56640 1.310 0.1922 
Speciessetosa:poly(Petal.Length, 2, raw = T)2  -1.12847 0.74087 -1.523 0.1299 
Speciesversicolor:poly(Petal.Length, 2, raw = T)2 -0.03641 0.09628 -0.378 0.7059 
Speciesvirginica:poly(Petal.Length, 2, raw = T)2 0.02178 0.05107 0.426 0.6705 
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.3367 on 143 degrees of freedom 
Multiple R-squared: 0.8413, Adjusted R-squared: 0.8346 
F-statistic: 126.4 on 6 and 143 DF, p-value: < 2.2e-16 

だから、違いは何ですか?式内の任意の形質転換に使用することができる -

まあ、私はあなたの他の質問で言っていたように、基本的にはそのI()はそれがはるかに柔軟だからR・プログラマの大半はlmglm式で使用するものです。

しかし、彼自身にはそれぞれ。 SOは意見に基づく質問を禁止しているので、私はその質問を「両方の問題を解決する」と解釈するつもりです。その答えは「はい」であり、「なぜ私は遍在的に使われているのですか?」答えは「どのような変革に対しても柔軟性があります」という答えです。 であるかどうかについては、合法的に質問したり答えたりすることはできませんが、プログラマーズスタックエクスチェンジ(または、最近彼らが何と呼んでいるか)やコードスタック交換を確認します。

関連する問題