Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Running Code
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
## 第五步:自變數與依變數之間的相關性檢證library(gmodels)# 獨立立場 vs. 美國因素CrossTable(TNSS2015$Q12n,TNSS2015$Q30n,prop.r=TRUE,prop.t=FALSE,prop.c=TRUE,prop.chisq=FALSE,chisq=TRUE)
Cell Contents
|-------------------------|
| N |
| N / Row Total |
| N / Col Total |
|-------------------------|
Total Observations in Table: 916
| TNSS2015$Q30n
TNSS2015$Q12n | 0 | 1 | Row Total |
--------------|-----------|-----------|-----------|
0 | 251 | 451 | 702 |
| 0.358 | 0.642 | 0.766 |
| 0.860 | 0.723 | |
--------------|-----------|-----------|-----------|
1 | 41 | 173 | 214 |
| 0.192 | 0.808 | 0.234 |
| 0.140 | 0.277 | |
--------------|-----------|-----------|-----------|
Column Total | 292 | 624 | 916 |
| 0.319 | 0.681 | |
--------------|-----------|-----------|-----------|
Statistics for All Table Factors
Pearson's Chi-squared test
------------------------------------------------------------
Chi^2 = 20.80134 d.f. = 1 p = 5.094721e-06
Pearson's Chi-squared test with Yates' continuity correction
------------------------------------------------------------
Chi^2 = 20.04412 d.f. = 1 p = 7.567574e-06
# 獨立立場 vs. 中共因素CrossTable(TNSS2015$Q12n,TNSS2015$Q27n,prop.r=TRUE,prop.t=FALSE,prop.c=TRUE,prop.chisq=FALSE,chisq=TRUE)
Cell Contents
|-------------------------|
| N |
| N / Row Total |
| N / Col Total |
|-------------------------|
Total Observations in Table: 942
| TNSS2015$Q27n
TNSS2015$Q12n | 0 | 1 | Row Total |
--------------|-----------|-----------|-----------|
0 | 237 | 489 | 726 |
| 0.326 | 0.674 | 0.771 |
| 0.707 | 0.806 | |
--------------|-----------|-----------|-----------|
1 | 98 | 118 | 216 |
| 0.454 | 0.546 | 0.229 |
| 0.293 | 0.194 | |
--------------|-----------|-----------|-----------|
Column Total | 335 | 607 | 942 |
| 0.356 | 0.644 | |
--------------|-----------|-----------|-----------|
Statistics for All Table Factors
Pearson's Chi-squared test
------------------------------------------------------------
Chi^2 = 11.76451 d.f. = 1 p = 0.0006037061
Pearson's Chi-squared test with Yates' continuity correction
------------------------------------------------------------
Chi^2 = 11.21574 d.f. = 1 p = 0.0008110655
# 美國因素 vs. 中共因素CrossTable(TNSS2015$Q30n,TNSS2015$Q27n,prop.r=TRUE,prop.t=FALSE,prop.c=TRUE,prop.chisq=FALSE,chisq=TRUE)
Cell Contents
|-------------------------|
| N |
| N / Row Total |
| N / Col Total |
|-------------------------|
Total Observations in Table: 842
| TNSS2015$Q27n
TNSS2015$Q30n | 0 | 1 | Row Total |
--------------|-----------|-----------|-----------|
0 | 72 | 200 | 272 |
| 0.265 | 0.735 | 0.323 |
| 0.240 | 0.369 | |
--------------|-----------|-----------|-----------|
1 | 228 | 342 | 570 |
| 0.400 | 0.600 | 0.677 |
| 0.760 | 0.631 | |
--------------|-----------|-----------|-----------|
Column Total | 300 | 542 | 842 |
| 0.356 | 0.644 | |
--------------|-----------|-----------|-----------|
Statistics for All Table Factors
Pearson's Chi-squared test
------------------------------------------------------------
Chi^2 = 14.6958 d.f. = 1 p = 0.0001263278
Pearson's Chi-squared test with Yates' continuity correction
------------------------------------------------------------
Chi^2 = 14.11181 d.f. = 1 p = 0.0001722588
## 第六步:假設檢證mod.1<-glm(Q12n ~ Q27n + Q30n, data=TNSS2015 , family ="binomial")summary(mod.1)
Call:
glm(formula = Q12n ~ Q27n + Q30n, family = "binomial", data = TNSS2015)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.4167 0.2039 -6.947 3.74e-12 ***
Q27n1 -0.4430 0.1674 -2.646 0.008155 **
Q30n1 0.7226 0.1952 3.702 0.000214 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 923.20 on 841 degrees of freedom
Residual deviance: 898.54 on 839 degrees of freedom
(229 observations deleted due to missingness)
AIC: 904.54
Number of Fisher Scoring iterations: 4