R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

We are trying to fit the kyphosis data with the GAM method. ##This is and incomplete work, only to be seen for a partner!!!

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk with the comand “´´´{r}”

## Loading required package: splines
## Loading required package: foreach
## Loaded gam 1.22
## [1] "The head of the data to be used in the training process"
##    Kyphosis Age Number Start
## 25   absent 131      2     3
## 1    absent  71      3     5
## 62   absent 102      3    13
## 64  present 114      7     8
## 12   absent 148      3    16
## 10  present  59      6    12
## [1] "and now the head of the data to be used in predictions"
##    Kyphosis Age Number Start
## 4    absent   2      5     1
## 6    absent   1      2    16
## 22   absent  22      2    16
## 29   absent   8      3     6
## 31   absent   4      3    16
## 33   absent  31      3    16
## GAM s.wam loop 1: deviance = 49.64933 
## GAM s.wam loop 2: deviance = 47.31545 
## GAM s.wam loop 3: deviance = 46.29691 
## GAM s.wam loop 4: deviance = 45.70711 
## GAM s.wam loop 5: deviance = 45.44348 
## GAM s.wam loop 6: deviance = 45.35662 
## GAM s.wam loop 7: deviance = 45.33547 
## GAM s.wam loop 8: deviance = 45.33114 
## GAM s.wam loop 9: deviance = 45.33029 
## GAM s.wam loop 10: deviance = 45.33013 
## GAM s.wam loop 11: deviance = 45.3301 
## GAM s.wam loop 12: deviance = 45.33009 
## GAM s.wam loop 13: deviance = 45.33009
## 
## Call: gam(formula = Kyphosis ~ s(Age, 4) + Number, family = binomial, 
##     data = kyph.training, trace = TRUE)
## Deviance Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.65777 -0.74780 -0.34854 -0.01102  2.18556 
## 
## (Dispersion Parameter for binomial family taken to be 1)
## 
##     Null Deviance: 65.1927 on 59 degrees of freedom
## Residual Deviance: 45.3301 on 53.9998 degrees of freedom
## AIC: 57.3305 
## 
## Number of Local Scoring Iterations: NA 
## 
## Anova for Parametric Effects
##           Df Sum Sq Mean Sq F value   Pr(>F)   
## s(Age, 4)  1  0.429  0.4291  0.5498 0.461621   
## Number     1  8.256  8.2564 10.5781 0.001975 **
## Residuals 54 42.148  0.7805                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Anova for Nonparametric Effects
##             Npar Df Npar Chisq P(Chi)
## (Intercept)                          
## s(Age, 4)         3     5.9373 0.1147
## Number
##     s(Age, 4)     Number
## 4  -2.1999570  0.4561159
## 6  -2.2479093 -1.4532064
## 22 -1.3191931 -1.4532064
## 29 -1.9149893 -0.8167656
## 31 -2.1042412 -0.8167656
## 33 -0.9407890 -0.8167656
## 38  0.6138317 -0.8167656
## 39 -2.2479093 -0.8167656
## 41 -1.3988071  1.0925566
## 43 -0.1966336  0.4561159
## 46 -0.2464173 -0.1803249
## 49 -0.1013489 -0.1803249
## 50  0.3249586  0.4561159
## 51  0.8388334 -0.8167656
## 52 -4.9611675 -1.4532064
## 54 -1.8684291 -1.4532064
## 59 -2.1999570 -0.8167656
## 67  0.9112785 -0.1803249
## 79 -2.5146546 -0.8167656
## 81  0.8667885 -1.4532064
## 83 -0.7255399 -0.1803249
## attr(,"constant")
## [1] -1.07123
## GAM s.wam loop 1: deviance = 48.06192 
## GAM s.wam loop 2: deviance = 44.95525 
## GAM s.wam loop 3: deviance = 43.67214 
## GAM s.wam loop 4: deviance = 43.04551 
## GAM s.wam loop 5: deviance = 42.80878 
## GAM s.wam loop 6: deviance = 42.73908 
## GAM s.wam loop 7: deviance = 42.72331 
## GAM s.wam loop 8: deviance = 42.72097 
## GAM s.wam loop 9: deviance = 42.72055 
## GAM s.wam loop 10: deviance = 42.72048 
## GAM s.wam loop 11: deviance = 42.72046 
## GAM s.wam loop 12: deviance = 42.72046
## 
## Call: gam(formula = Kyphosis ~ s(Age, 4) + s(Number, 4), family = binomial, 
##     data = kyph.training, trace = TRUE)
## Deviance Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.33716 -0.68978 -0.29316 -0.01484  2.14117 
## 
## (Dispersion Parameter for binomial family taken to be 1)
## 
##     Null Deviance: 65.1927 on 59 degrees of freedom
## Residual Deviance: 42.7205 on 51.0001 degrees of freedom
## AIC: 60.7203 
## 
## Number of Local Scoring Iterations: NA 
## 
## Anova for Parametric Effects
##              Df Sum Sq Mean Sq F value   Pr(>F)   
## s(Age, 4)     1  1.349  1.3485  1.7762 0.188534   
## s(Number, 4)  1  7.697  7.6969 10.1384 0.002476 **
## Residuals    51 38.718  0.7592                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Anova for Nonparametric Effects
##              Npar Df Npar Chisq P(Chi)
## (Intercept)                           
## s(Age, 4)          3     5.9463 0.1142
## s(Number, 4)       3     2.6705 0.4453
##     s(Age, 4) s(Number, 4)
## 4  -2.2160604    0.6740591
## 6  -2.2593451   -2.7699914
## 22 -1.4145543   -2.7699914
## 29 -1.9585781   -1.1215605
## 31 -2.1296478   -1.1215605
## 33 -1.0633294   -1.1215605
## 38  0.6462161   -1.1215605
## 39 -2.2593451   -1.1215605
## 41 -1.4879770    1.6010805
## 43 -0.3202441    0.6740591
## 46 -0.4174279   -0.1644021
## 49  0.3208429   -0.1644021
## 50  0.6751306    0.6740591
## 51  1.0832773   -1.1215605
## 52 -4.1815587   -2.7699914
## 54 -1.9164119   -2.7699914
## 59 -2.2160604   -1.1215605
## 67  1.1332297   -0.1644021
## 79 -1.8609915   -1.1215605
## 81  1.1033650   -2.7699914
## 83 -0.8640442   -0.1644021
## attr(,"constant")
## [1] -1.126854

Including Plots

You can also embed plots, for example:

plot( Gam.Kyph2,se=TRUE) Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.