SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
R
            ,

 19         ( 22   )

2012/1/26
R           : lm()   ,R

        :            ,             ,
    ,            ,

                         : glm()
R

R



R   lm
         lm
: Edgar Anderson’s Iris Data
R



help(package=”datasets”)

         iris                       150
(           50      : Species
    (Sepal.Length , Sepal.Width )
(Petal.Length , Petal.Width )
> m1 <- lm(Sepal.Length ~ Petal.Length, data=iris)
> m1
 Call:
 lm(formula = Sepal.Length ~ Petal.Length, data = iris)
 Coefficients:
 (Intercept) Petal.Length
    4.3066      0.4089

• iris                    Sepal.Length         Petal.Length


   m1

• m1
> summary(m1)
 Call:
 lm(formula = Sepal.Length ~ Petal.Length, data = iris)
 Residuals:
     Min     1Q Median         3Q     Max
 -1.24675 -0.29657 -0.01515 0.27676 1.00269
 Coefficients:
               Estimate Std. Error t value Pr(>|t|)
 (Intercept)   4.30660 0.07839 54.94 <2e-16 ***
 Petal.Length 0.40892 0.01889 21.65 <2e-16 ***
 ---
 Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 (                   )

•                                 summary


                                           summary               coef   fitted   ,
    residuals
(                       )
Residual standard error: 0.4071 on 148 degrees of freedom
Multiple R-squared: 0.76,	 Adjusted R-squared: 0.7583
F-statistic: 468.6 on 1 and 148 DF, p-value: < 2.2e-16



     • summary                             ,                       ,
              =0                       t          (           ),       ,
       R2,         R2,             F

     • coef                                       fitted
                                                  residuals
> m2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data=iris)
> m2
Call:
lm(formula = Sepal.Length ~ Petal.Length + Petal.Width, data = iris)
Coefficients:
 (Intercept) Petal.Length Petal.Width
    4.1906      0.5418    -0.3196

• Petal.Width
• iris                Sepal.Length     Petal.Length    Petal.Width
                                                  m2

• m2
> summary(m2)
( )
Coefficients:
             Estimate Std. Error t value   Pr(>|t|)
(Intercept)  4.19058 0.09705 43.181        < 2e-16 ***
Petal.Length 0.54178 0.06928 7.820         9.41e-13 ***
Petal.Width -0.31955 0.16045 -1.992        0.0483 *
( )
Residual standard error: 0.4031 on 147 degrees of freedom
Multiple R-squared: 0.7663,	 Adjusted R-squared: 0.7631
F-statistic: 241 on 2 and 147 DF, p-value: < 2.2e-16
• summary
> m2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data=iris)

                                ”~”

                  ”+”



                                      data
> m3 <- lm(Sepal.Length ~ Petal.Length + Petal.Width +
Petal.Length:Petal.Width , data=iris)

                                        ”:”


   2
                            “*”
> m3d <- lm(Sepal.Length ~ Petal.Length * Petal.Width ,data=iris)

         m3      m3d
> m4 <- lm(Sepal.Length ~ Petal.Length^2 , data=iris)
   > m4 <- lm(Sepal.Length ~ I(Petal.Length^2) , data=iris)

“^” “+” “-” ”*” “:”

                                        I(           i)
> m5 <- lm(Sepal.Length ~ Petal.Length + Species, data=iris)
> summary(m5)
( )
Coefficients:
                   Estimate Std. Error t value Pr(>|t|)
(Intercept)        3.68353 0.10610 34.719 < 2e-16 ***
Petal.Length       0.90456 0.06479 13.962 < 2e-16 ***
Speciesversicolor -1.60097 0.19347 -8.275 7.37e-14 ***
Speciesvirginica -2.11767 0.27346 -7.744 1.48e-12 ***
( )
   Species     factor (“setosa”, “versicolor”, “virginica”        )

   factor                                                    -1
   (Speciesversicolor, Speciesvirginica)
> m2
Call:
lm(formula = Sepal.Length ~ Petal.Length + Petal.Width, data = iris)
Coefficients:
 (Intercept) Petal.Length Petal.Width
     4.1906      0.5418        -0.3196
> coef(m2)
 (Intercept) Petal.Length Petal.Width
   4.1905824 0.5417772 -0.3195506
> sd(iris$Petal.Length) / sd(iris$Sepal.Length)
[1] 2.131832
> sd(iris$Petal.Width) / sd(iris$Sepal.Length)
[1] 0.9205034
> 0.5417772 * 2.131832
[1] 1.154978
> -0.3195506 * 0.9205034
[1] -0.2941474
> coef(m2)[-1] * apply(m2$model[-1],2,sd) / sd(m2$model[,1])
Petal.Length Petal.Width
   1.1549781 -0.2941474
> cor(iris[,1:4])
             Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411
Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259
Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654
Petal.Width   0.8179411 -0.3661259 0.9628654 1.0000000



                    (factor)            5   (Species )
                               iris[,1:4]   cor
> m6 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width
+ Species, data = iris)
> step(m6)
Start: AIC=-348.57
Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species
              Df Sum of Sq RSS AIC
<none>                      13.556 -348.57
- Petal.Width 1 0.4090      13.966 -346.11
- Species      2 0.8889 14.445 -343.04
- Sepal.Width 1 3.1250 16.681 -319.45
- Petal.Length 1 13.7853 27.342 -245.33

   step           AIC(                )
                   AIC
(Residual-Fitted plot)
  > m1 <- lm(Sepal.Length ~ Petal.Length, data=iris)
  > m6 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width
  + Species, data = iris)
  > plot(m1, which=1)
  > plot(m6, which=1)
                                Residuals vs Fitted                                                         Residuals vs Fitted
            1.0




                   15                                       132                                        15                      136




                                                                                    0.5
            0.5
Residuals




                                                                        Residuals
            0.0




                                                                                    0.0
            -0.5




                                                                                    -0.5
            -1.0




                                          107                                                                       85
            -1.5




                    5.0         5.5      6.0          6.5         7.0                      4.5   5.0        5.5   6.0    6.5      7.0   7.5   8.0

                                   Fitted values                                                   Fitted values
                          lm(Sepal.Length ~ Petal.Length)               lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species)
(                                           q-q plot)
> m1 <- lm(Sepal.Length ~ Petal.Length, data=iris)
> m6 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width
+ Species, data = iris)
> plot(m1, which=2)
> plot(m6, which=2)
                                                        Normal Q-Q                                                                   Normal Q-Q




                                                                                                                 3
                             3




                                                                               132 15                                                                 15 136




                                                                                                                 2
                             2
    Standardized residuals




                                                                                        Standardized residuals
                             1




                                                                                                                 1
                             0




                                                                                                                 0
                             -1




                                                                                                                 -1
                             -2




                                                                                                                 -2
                             -3




                                  107                                                                                 85


                                        -2         -1       0        1         2                                           -2   -1       0        1   2

                                                  Theoretical Quantiles                                          Theoretical Quantiles
                                             lm(Sepal.Length ~ Petal.Length)             lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species)
glm

glm   lm
: data from a case-control study of
esophagaeal cancer in Ile-et-Vilaine, France
 R                                              esoph



 agegp(Age group, 6 ), alcgp(Alcohol consumption, 4 ),
 tobgp(Tobacco consumption, 4 ), ncases (number of
 cases), ncontrols(number of controls) 5

 agegp, alcgp, tobgp             case control
> m7 <- glm(cbind(ncases, ncontrols) ~ agegp+tobgp+alcgp,
data=esoph, family=binomial,contrasts=list(agegp="contr.treatment",
tobgp="contr.treatment", alcgp="contr.treatment"))

•   esoph                                    agegp     tobgp   alcgp
                                                      m7

•   1              1            0 or 1
            iris                                     ” ”

•   “family=binomial”



•   contrasts
                            (            )
                   factor
> summary(m7)
( )
Deviance Residuals:
    Min     1Q Median        3Q      Max
-1.6891 -0.5618 -0.2168 0.2314 2.0642
Coefficients:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)    -5.9108 1.0302 -5.737 9.61e-09 ***
agegp35-44 1.6095 1.0676 1.508 0.131652
agegp45-54 2.9752 1.0242 2.905 0.003675 **
agegp55-64 3.3584 1.0198 3.293 0.000991 ***
agegp65-74 3.7270 1.0253 3.635 0.000278 ***
agegp75+        3.6818 1.0645 3.459 0.000543 ***
tobgp10-19 0.3407 0.2054 1.659 0.097159 .
tobgp20-29 0.3962 0.2456 1.613 0.106708
tobgp30+        0.8677 0.2765 3.138 0.001701 **
alcgp40-79 1.1216 0.2384 4.704 2.55e-06 ***
alcgp80-119 1.4471 0.2628 5.506 3.68e-08 ***
alcgp120+       2.1154 0.2876 7.356 1.90e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 227.241 on 87 degrees of freedom
Residual deviance: 53.973 on 76 degrees of freedom
AIC: 225.45
Number of Fisher Scoring iterations: 6
summary

lm Residual          Deviance(         )



              Wald       z                 =0



                                 AIC
> exp(cbind(coef(m7),confint(m7)))
Waiting for profiling to be done...
                                   2.5 %      97.5 %
(Intercept)    0.002710046 0.0001500676     0.01309911
agegp35-44 5.000426461 0.9048631872         93.44857822
agegp45-54 19.592860766 4.1082301889       351.60508496
agegp55-64 28.741838956 6.1156513661       513.64343522
agegp65-74 41.554820823 8.6954216578       746.54178414
agegp75+       39.716132031 7.3282690051   740.73696224
tobgp10-19 1.405982889 0.9376683713        2.10030180
tobgp20-29 1.486221090 0.9107730044        2.39108827
tobgp30+      2.381435327 1.3753149494     4.07656452
alcgp40-79 3.069638047 1.9438541677        4.96418587
alcgp80-119 4.250811157 2.5569142185       7.18622034
alcgp120+ 8.292938857 4.7505293148         14.70778864

                      95%                    confint



                            95%                           exp
                           95%
Web
R    3500                                  R



              Epi, epicalc, epitools,epiR, epibasix
                            2x2                  APC
    , Mantel-Haenszel
Web                 ,
RjpWiki :
     Q and A



R-bloggers : R



inside-R : R                         Revolution R



Twitter:         #rstats, #rstatsj
“R               ”

slideshare.net       Twitter             R
                               Ustream


                                   R
R

Contenu connexe

En vedette

20140827 about OpenStreetMap
20140827 about OpenStreetMap20140827 about OpenStreetMap
20140827 about OpenStreetMapTaichi Furuhashi
 
災害拠点病院とは?
災害拠点病院とは?災害拠点病院とは?
災害拠点病院とは?Yuichi Kuroki
 
地震・津波・液状化と院内災害対応
地震・津波・液状化と院内災害対応地震・津波・液状化と院内災害対応
地震・津波・液状化と院内災害対応Yuichi Kuroki
 
R stan導入公開版
R stan導入公開版R stan導入公開版
R stan導入公開版考司 小杉
 
病院内における災害時行動の原則
病院内における災害時行動の原則病院内における災害時行動の原則
病院内における災害時行動の原則Yuichi Kuroki
 
災害医療に役立つ標語集
災害医療に役立つ標語集災害医療に役立つ標語集
災害医療に役立つ標語集Yuichi Kuroki
 
一般化線形混合モデル入門の入門
一般化線形混合モデル入門の入門一般化線形混合モデル入門の入門
一般化線形混合モデル入門の入門Yu Tamura
 
エクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてエクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてHiroshi Shimizu
 

En vedette (8)

20140827 about OpenStreetMap
20140827 about OpenStreetMap20140827 about OpenStreetMap
20140827 about OpenStreetMap
 
災害拠点病院とは?
災害拠点病院とは?災害拠点病院とは?
災害拠点病院とは?
 
地震・津波・液状化と院内災害対応
地震・津波・液状化と院内災害対応地震・津波・液状化と院内災害対応
地震・津波・液状化と院内災害対応
 
R stan導入公開版
R stan導入公開版R stan導入公開版
R stan導入公開版
 
病院内における災害時行動の原則
病院内における災害時行動の原則病院内における災害時行動の原則
病院内における災害時行動の原則
 
災害医療に役立つ標語集
災害医療に役立つ標語集災害医療に役立つ標語集
災害医療に役立つ標語集
 
一般化線形混合モデル入門の入門
一般化線形混合モデル入門の入門一般化線形混合モデル入門の入門
一般化線形混合モデル入門の入門
 
エクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてエクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについて
 

Similaire à 第19回疫学セミナー 統計解析ソフトRの活用「Rで線形モデル」

ITS World Congress :: Vienna, Oct 2012
ITS World Congress :: Vienna, Oct 2012ITS World Congress :: Vienna, Oct 2012
ITS World Congress :: Vienna, Oct 2012László Nádai
 
Radar 2009 a 3 review of signals, systems, and dsp
Radar 2009 a  3 review of signals, systems, and dspRadar 2009 a  3 review of signals, systems, and dsp
Radar 2009 a 3 review of signals, systems, and dspVi Binh Q. Le
 
Radar 2009 a 3 review of signals systems and dsp
Radar 2009 a  3 review of signals systems and dspRadar 2009 a  3 review of signals systems and dsp
Radar 2009 a 3 review of signals systems and dspForward2025
 
Radar 2009 a 3 review of signals, systems, and dsp
Radar 2009 a  3 review of signals, systems, and dspRadar 2009 a  3 review of signals, systems, and dsp
Radar 2009 a 3 review of signals, systems, and dspsubha5
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdfzehiwot hone
 
QUESTION 1 ( no explanation needed please help to answer all not just.pdf
QUESTION 1 ( no explanation needed please help to answer all not just.pdfQUESTION 1 ( no explanation needed please help to answer all not just.pdf
QUESTION 1 ( no explanation needed please help to answer all not just.pdfPhilzIGHudsonl
 
ICF Presentation 1
ICF Presentation 1ICF Presentation 1
ICF Presentation 1nirajreiki
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsAnh Dung NGUYEN
 
11. Linear Models
11. Linear Models11. Linear Models
11. Linear ModelsFAO
 
Linear models
Linear modelsLinear models
Linear modelsFAO
 
Durbib- Watson D between 0-2 means there is a positive correlati
Durbib- Watson D between 0-2 means there is a positive correlatiDurbib- Watson D between 0-2 means there is a positive correlati
Durbib- Watson D between 0-2 means there is a positive correlatiAlyciaGold776
 
#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx
#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx
#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docxkatherncarlyle
 
Mini project boston housing dataset v1
Mini project   boston housing dataset v1Mini project   boston housing dataset v1
Mini project boston housing dataset v1Wyendrila Roy
 
Bayesian Defect Signal Analysis for Nondestructive Evaluation of Materials
Bayesian Defect Signal Analysis for Nondestructive Evaluation of MaterialsBayesian Defect Signal Analysis for Nondestructive Evaluation of Materials
Bayesian Defect Signal Analysis for Nondestructive Evaluation of MaterialsAleksandar Dogandžić
 
10 range and doppler measurements in radar systems
10 range and doppler measurements in radar systems10 range and doppler measurements in radar systems
10 range and doppler measurements in radar systemsSolo Hermelin
 

Similaire à 第19回疫学セミナー 統計解析ソフトRの活用「Rで線形モデル」 (20)

Oil Prices Data Analysis - R
Oil Prices Data Analysis - ROil Prices Data Analysis - R
Oil Prices Data Analysis - R
 
ITS World Congress :: Vienna, Oct 2012
ITS World Congress :: Vienna, Oct 2012ITS World Congress :: Vienna, Oct 2012
ITS World Congress :: Vienna, Oct 2012
 
Radar 2009 a 3 review of signals, systems, and dsp
Radar 2009 a  3 review of signals, systems, and dspRadar 2009 a  3 review of signals, systems, and dsp
Radar 2009 a 3 review of signals, systems, and dsp
 
Radar 2009 a 3 review of signals systems and dsp
Radar 2009 a  3 review of signals systems and dspRadar 2009 a  3 review of signals systems and dsp
Radar 2009 a 3 review of signals systems and dsp
 
Radar 2009 a 3 review of signals, systems, and dsp
Radar 2009 a  3 review of signals, systems, and dspRadar 2009 a  3 review of signals, systems, and dsp
Radar 2009 a 3 review of signals, systems, and dsp
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdf
 
QUESTION 1 ( no explanation needed please help to answer all not just.pdf
QUESTION 1 ( no explanation needed please help to answer all not just.pdfQUESTION 1 ( no explanation needed please help to answer all not just.pdf
QUESTION 1 ( no explanation needed please help to answer all not just.pdf
 
ICF Presentation 1
ICF Presentation 1ICF Presentation 1
ICF Presentation 1
 
Wireless
WirelessWireless
Wireless
 
Representation image
Representation imageRepresentation image
Representation image
 
Descriptive Statistics in R.pptx
Descriptive Statistics in R.pptxDescriptive Statistics in R.pptx
Descriptive Statistics in R.pptx
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion Sets
 
11. Linear Models
11. Linear Models11. Linear Models
11. Linear Models
 
Linear models
Linear modelsLinear models
Linear models
 
Durbib- Watson D between 0-2 means there is a positive correlati
Durbib- Watson D between 0-2 means there is a positive correlatiDurbib- Watson D between 0-2 means there is a positive correlati
Durbib- Watson D between 0-2 means there is a positive correlati
 
#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx
#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx
#HW6, R output getSymbols(AMZN,from=2004-01-05,to=2012-05-.docx
 
12. Linear models
12. Linear models12. Linear models
12. Linear models
 
Mini project boston housing dataset v1
Mini project   boston housing dataset v1Mini project   boston housing dataset v1
Mini project boston housing dataset v1
 
Bayesian Defect Signal Analysis for Nondestructive Evaluation of Materials
Bayesian Defect Signal Analysis for Nondestructive Evaluation of MaterialsBayesian Defect Signal Analysis for Nondestructive Evaluation of Materials
Bayesian Defect Signal Analysis for Nondestructive Evaluation of Materials
 
10 range and doppler measurements in radar systems
10 range and doppler measurements in radar systems10 range and doppler measurements in radar systems
10 range and doppler measurements in radar systems
 

Plus de Masafumi Okada

Rとkerasを使った臨床試験登録情報のテキスト分類
Rとkerasを使った臨床試験登録情報のテキスト分類Rとkerasを使った臨床試験登録情報のテキスト分類
Rとkerasを使った臨床試験登録情報のテキスト分類Masafumi Okada
 
Rとcdisc@moss10 公開用
Rとcdisc@moss10 公開用Rとcdisc@moss10 公開用
Rとcdisc@moss10 公開用Masafumi Okada
 
Rmpiとsnowで 並列処理
Rmpiとsnowで 並列処理Rmpiとsnowで 並列処理
Rmpiとsnowで 並列処理Masafumi Okada
 
FOSS4G 2009 Tokyo (R and Geo) in Japanese
FOSS4G 2009 Tokyo (R and Geo) in JapaneseFOSS4G 2009 Tokyo (R and Geo) in Japanese
FOSS4G 2009 Tokyo (R and Geo) in JapaneseMasafumi Okada
 

Plus de Masafumi Okada (7)

Rとkerasを使った臨床試験登録情報のテキスト分類
Rとkerasを使った臨床試験登録情報のテキスト分類Rとkerasを使った臨床試験登録情報のテキスト分類
Rとkerasを使った臨床試験登録情報のテキスト分類
 
RとIoT
RとIoTRとIoT
RとIoT
 
Rとcdisc@moss10 公開用
Rとcdisc@moss10 公開用Rとcdisc@moss10 公開用
Rとcdisc@moss10 公開用
 
RとCDISC
RとCDISCRとCDISC
RとCDISC
 
R新機能抄出
R新機能抄出R新機能抄出
R新機能抄出
 
Rmpiとsnowで 並列処理
Rmpiとsnowで 並列処理Rmpiとsnowで 並列処理
Rmpiとsnowで 並列処理
 
FOSS4G 2009 Tokyo (R and Geo) in Japanese
FOSS4G 2009 Tokyo (R and Geo) in JapaneseFOSS4G 2009 Tokyo (R and Geo) in Japanese
FOSS4G 2009 Tokyo (R and Geo) in Japanese
 

Dernier

The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsEugene Lysak
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
How to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeHow to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeCeline George
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
A gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceA gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceApostolos Syropoulos
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...M56BOOKSTORE PRODUCT/SERVICE
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSyedNadeemGillANi
 

Dernier (20)

The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George Wells
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
How to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using CodeHow to Send Emails From Odoo 17 Using Code
How to Send Emails From Odoo 17 Using Code
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
A gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceA gentle introduction to Artificial Intelligence
A gentle introduction to Artificial Intelligence
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic SupportMarch 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...KARNAADA.pptx  made by -  saransh dwivedi ( SD ) -  SHALAKYA TANTRA - ENT - 4...
KARNAADA.pptx made by - saransh dwivedi ( SD ) - SHALAKYA TANTRA - ENT - 4...
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
 

第19回疫学セミナー 統計解析ソフトRの活用「Rで線形モデル」

  • 1. R , 19 ( 22 ) 2012/1/26
  • 2. R : lm() ,R : , , , , : glm()
  • 3. R R R lm lm
  • 4. : Edgar Anderson’s Iris Data R help(package=”datasets”) iris 150 ( 50 : Species (Sepal.Length , Sepal.Width ) (Petal.Length , Petal.Width )
  • 5. > m1 <- lm(Sepal.Length ~ Petal.Length, data=iris) > m1 Call: lm(formula = Sepal.Length ~ Petal.Length, data = iris) Coefficients: (Intercept) Petal.Length 4.3066 0.4089 • iris Sepal.Length Petal.Length m1 • m1
  • 6. > summary(m1) Call: lm(formula = Sepal.Length ~ Petal.Length, data = iris) Residuals: Min 1Q Median 3Q Max -1.24675 -0.29657 -0.01515 0.27676 1.00269 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.30660 0.07839 54.94 <2e-16 *** Petal.Length 0.40892 0.01889 21.65 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 ( ) • summary summary coef fitted , residuals
  • 7. ( ) Residual standard error: 0.4071 on 148 degrees of freedom Multiple R-squared: 0.76, Adjusted R-squared: 0.7583 F-statistic: 468.6 on 1 and 148 DF, p-value: < 2.2e-16 • summary , , =0 t ( ), , R2, R2, F • coef fitted residuals
  • 8. > m2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data=iris) > m2 Call: lm(formula = Sepal.Length ~ Petal.Length + Petal.Width, data = iris) Coefficients: (Intercept) Petal.Length Petal.Width 4.1906 0.5418 -0.3196 • Petal.Width • iris Sepal.Length Petal.Length Petal.Width m2 • m2
  • 9. > summary(m2) ( ) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.19058 0.09705 43.181 < 2e-16 *** Petal.Length 0.54178 0.06928 7.820 9.41e-13 *** Petal.Width -0.31955 0.16045 -1.992 0.0483 * ( ) Residual standard error: 0.4031 on 147 degrees of freedom Multiple R-squared: 0.7663, Adjusted R-squared: 0.7631 F-statistic: 241 on 2 and 147 DF, p-value: < 2.2e-16 • summary
  • 10. > m2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data=iris) ”~” ”+” data
  • 11. > m3 <- lm(Sepal.Length ~ Petal.Length + Petal.Width + Petal.Length:Petal.Width , data=iris) ”:” 2 “*” > m3d <- lm(Sepal.Length ~ Petal.Length * Petal.Width ,data=iris) m3 m3d
  • 12. > m4 <- lm(Sepal.Length ~ Petal.Length^2 , data=iris) > m4 <- lm(Sepal.Length ~ I(Petal.Length^2) , data=iris) “^” “+” “-” ”*” “:” I( i)
  • 13. > m5 <- lm(Sepal.Length ~ Petal.Length + Species, data=iris) > summary(m5) ( ) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.68353 0.10610 34.719 < 2e-16 *** Petal.Length 0.90456 0.06479 13.962 < 2e-16 *** Speciesversicolor -1.60097 0.19347 -8.275 7.37e-14 *** Speciesvirginica -2.11767 0.27346 -7.744 1.48e-12 *** ( ) Species factor (“setosa”, “versicolor”, “virginica” ) factor -1 (Speciesversicolor, Speciesvirginica)
  • 14. > m2 Call: lm(formula = Sepal.Length ~ Petal.Length + Petal.Width, data = iris) Coefficients: (Intercept) Petal.Length Petal.Width 4.1906 0.5418 -0.3196 > coef(m2) (Intercept) Petal.Length Petal.Width 4.1905824 0.5417772 -0.3195506 > sd(iris$Petal.Length) / sd(iris$Sepal.Length) [1] 2.131832 > sd(iris$Petal.Width) / sd(iris$Sepal.Length) [1] 0.9205034 > 0.5417772 * 2.131832 [1] 1.154978 > -0.3195506 * 0.9205034 [1] -0.2941474 > coef(m2)[-1] * apply(m2$model[-1],2,sd) / sd(m2$model[,1]) Petal.Length Petal.Width 1.1549781 -0.2941474
  • 15. > cor(iris[,1:4]) Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411 Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259 Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654 Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000 (factor) 5 (Species ) iris[,1:4] cor
  • 16. > m6 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species, data = iris) > step(m6) Start: AIC=-348.57 Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species Df Sum of Sq RSS AIC <none> 13.556 -348.57 - Petal.Width 1 0.4090 13.966 -346.11 - Species 2 0.8889 14.445 -343.04 - Sepal.Width 1 3.1250 16.681 -319.45 - Petal.Length 1 13.7853 27.342 -245.33 step AIC( ) AIC
  • 17. (Residual-Fitted plot) > m1 <- lm(Sepal.Length ~ Petal.Length, data=iris) > m6 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species, data = iris) > plot(m1, which=1) > plot(m6, which=1) Residuals vs Fitted Residuals vs Fitted 1.0 15 132 15 136 0.5 0.5 Residuals Residuals 0.0 0.0 -0.5 -0.5 -1.0 107 85 -1.5 5.0 5.5 6.0 6.5 7.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 Fitted values Fitted values lm(Sepal.Length ~ Petal.Length) lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species)
  • 18. ( q-q plot) > m1 <- lm(Sepal.Length ~ Petal.Length, data=iris) > m6 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species, data = iris) > plot(m1, which=2) > plot(m6, which=2) Normal Q-Q Normal Q-Q 3 3 132 15 15 136 2 2 Standardized residuals Standardized residuals 1 1 0 0 -1 -1 -2 -2 -3 107 85 -2 -1 0 1 2 -2 -1 0 1 2 Theoretical Quantiles Theoretical Quantiles lm(Sepal.Length ~ Petal.Length) lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species)
  • 19. glm glm lm
  • 20. : data from a case-control study of esophagaeal cancer in Ile-et-Vilaine, France R esoph agegp(Age group, 6 ), alcgp(Alcohol consumption, 4 ), tobgp(Tobacco consumption, 4 ), ncases (number of cases), ncontrols(number of controls) 5 agegp, alcgp, tobgp case control
  • 21. > m7 <- glm(cbind(ncases, ncontrols) ~ agegp+tobgp+alcgp, data=esoph, family=binomial,contrasts=list(agegp="contr.treatment", tobgp="contr.treatment", alcgp="contr.treatment")) • esoph agegp tobgp alcgp m7 • 1 1 0 or 1 iris ” ” • “family=binomial” • contrasts ( ) factor
  • 22. > summary(m7) ( ) Deviance Residuals: Min 1Q Median 3Q Max -1.6891 -0.5618 -0.2168 0.2314 2.0642 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -5.9108 1.0302 -5.737 9.61e-09 *** agegp35-44 1.6095 1.0676 1.508 0.131652 agegp45-54 2.9752 1.0242 2.905 0.003675 ** agegp55-64 3.3584 1.0198 3.293 0.000991 *** agegp65-74 3.7270 1.0253 3.635 0.000278 *** agegp75+ 3.6818 1.0645 3.459 0.000543 *** tobgp10-19 0.3407 0.2054 1.659 0.097159 . tobgp20-29 0.3962 0.2456 1.613 0.106708 tobgp30+ 0.8677 0.2765 3.138 0.001701 ** alcgp40-79 1.1216 0.2384 4.704 2.55e-06 *** alcgp80-119 1.4471 0.2628 5.506 3.68e-08 *** alcgp120+ 2.1154 0.2876 7.356 1.90e-13 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 227.241 on 87 degrees of freedom Residual deviance: 53.973 on 76 degrees of freedom AIC: 225.45 Number of Fisher Scoring iterations: 6
  • 23. summary lm Residual Deviance( ) Wald z =0 AIC
  • 24. > exp(cbind(coef(m7),confint(m7))) Waiting for profiling to be done... 2.5 % 97.5 % (Intercept) 0.002710046 0.0001500676 0.01309911 agegp35-44 5.000426461 0.9048631872 93.44857822 agegp45-54 19.592860766 4.1082301889 351.60508496 agegp55-64 28.741838956 6.1156513661 513.64343522 agegp65-74 41.554820823 8.6954216578 746.54178414 agegp75+ 39.716132031 7.3282690051 740.73696224 tobgp10-19 1.405982889 0.9376683713 2.10030180 tobgp20-29 1.486221090 0.9107730044 2.39108827 tobgp30+ 2.381435327 1.3753149494 4.07656452 alcgp40-79 3.069638047 1.9438541677 4.96418587 alcgp80-119 4.250811157 2.5569142185 7.18622034 alcgp120+ 8.292938857 4.7505293148 14.70778864 95% confint 95% exp 95%
  • 25. Web
  • 26. R 3500 R Epi, epicalc, epitools,epiR, epibasix 2x2 APC , Mantel-Haenszel
  • 27. Web , RjpWiki : Q and A R-bloggers : R inside-R : R Revolution R Twitter: #rstats, #rstatsj
  • 28. “R ” slideshare.net Twitter R Ustream R
  • 29. R

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n