日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

儿童视力数据(2)

發布時間:2025/4/5 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 儿童视力数据(2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

接上文

生成一個近視指標。看看不同年齡段的近視比例

df['idx_of_nearSight'] = (df['sight_impaired'] == True ) & ((df['right_s'] < -0.5) |(df['left_s'] < -0.5))df['idx_of_nearSight'].value_counts()df.groupby('type')['idx_of_nearSight'].value_counts(normalize=True).unstack()

?這里可以看出近視比例隨著學段,不斷上升了

那么做一個卡方檢驗。

crs_of_nearSight = df.groupby('type')['idx_of_nearSight'].value_counts(normalize=True).unstack() crs_of_nearSight

import scipy.stats as ss ss.chi2_contingency(crs_of_nearSight)

保存crs_of_nearSight是為了后面用。

這樣就可以得到卡方檢驗的結果。

crs_of_nearSight = df.groupby('type')['idx_of_nearSight'].value_counts().unstack() crs_of_nearSightimport scipy.stats as ss ss.chi2_contingency(crs_of_nearSight)

?卡方檢驗必須用絕對數,所以 value_counts()里面的normalize不能有。

?結果,χ2值是1244,非常大,非常顯著。

為了寫到論文里面,把這個表格賦值到剪切板里。發送到excel。好編輯。

import scipy.stats as ss ss.chi2_contingency(crs_of_nearSight) crs_of_nearSighty = ss.chi2_contingency(crs_of_nearSight) y crs_of_nearSight.loc['chi2'] = y[0] crs_of_nearSight.loc['P'] = y[1] crs_of_nearSight crs_of_nearSight.to_clipboard()

?

?

?

?刪去chi2和P的后面的格就可以。

接下來可以看各個年級的近視率了。

這里生成一個交叉表,還是需要reindex

用pivot_table 也是可以的。

pd.pivot_table(index='nianji', data=df)['idx_of_nearSight']

?

x = pd.pivot_table(index='nianji', data=df)['idx_of_nearSight'] nianji_order x.reindex(nianji_order)

?

y = x.reindex(nianji_order) plt.plot(y) plt.xticks(rotation=45)

?得到近視率

?可以看出,近視率從小學到初中,一路攀升。

這里也可以用crosstab

pd.crosstab(index = df['nianji'], columns = df['idx_of_nearSight'])

?可以得到各個年級的近視人數。

?還是做一個圖

pd.crosstab(index = df['nianji'], columns = df['idx_of_nearSight'], normalize = 'index') pd.crosstab(index = df['nianji'], columns = df['idx_of_nearSight'], margins='row')

?算百分比的。

?

?列出行總數的。

?當然這個表也可以計算卡方。

還是做一個圖。

x = pd.crosstab(index = df['nianji'], columns = df['idx_of_nearSight'], normalize = 'index')[True]fig, ax = plt.subplots() ax.plot(x.reindex(nianji_order)) ax.set_xticklabels(labels = nianji_order, rotation= 45)

?

另外還想分男女生作圖。

pd.pivot_table(index='nianji', columns = 'sex', data= df)['idx_of_nearSight']

?用pivot_table 比較簡潔。

?

也可以用grouby或者crosstab

x = df.groupby(['nianji', 'sex'])['idx_of_nearSight'].mean().unstack() x.reindex(nianji_order)

?

?可以得到結果。

做一個圖看看。

plt.plot(x.reindex(nianji_order))

?

?

?發現,沒有標明男女,那還是分別作圖。

fig, ax = plt.subplots() ax.plot(y['男'], label = '男生') ax.plot(y['女'], label = '女生') plt.legend() plt.xticks(rotation=45)

?

?發現,小學階段,女生近視率比男生高,一直到初中,初中階段也是女生近視率略高,這可能是因為,女生都比男生愛學習???

?另外一個任務就是,區分 視力不良的程度。 5.0當然是最好的,4.9算是輕度,4.6-4.8算是中度不良,4.5及以下,就是重度。

#---------------------------------------------------------# #---- * 區分,輕度,重度,中度 * ----# #---------------------------------------------------------#xx = pd.cut(df['left'], bins = [0, 4.6, 4.85, 4.95, 6], right = True, labels = ["bad", "mid", "little", "good"]) xx.value_counts() yy = pd.cut(df['left'], bins = [0, 4.6, 4.85, 4.95, 6], right = True) yy.value_counts()

?

?

?

?可以看出,good的是5.0的。4.6-4.9的是輕度,單純從左眼來看。

視力好的,有4933個人。輕度不良的(4.9)的有1007.因為區間是 (4.85, 4.95】

中度的是1471,區間是(4.55, 4.85】,重度的是 1366,區間是4.5及以下。

視力不良判別,程度判斷指標,只能分開左右眼來判斷。分組也很麻煩。左右眼判斷要分別開。這個就不做了。

比較簡單的是分左右眼,統計均值。

pd.pivot_table(index='nianji', columns = ['sex'], values =['right', 'left'] , data = df)pd.crosstab(index = df['nianji'], columns=df['sex'], values=df['right'], aggfunc = 'mean') pd.crosstab(index = df['nianji'], columns=df['sex'], values= df['left'], aggfunc = 'mean')df.groupby(['nianji', 'sex'])['right', 'left'].mean().unstack()

?上述三種方式,都可以。

x = df.groupby(['nianji', 'sex'])['right', 'left'].mean().unstack()x

?用groupby。

?

x = x.reindex(nianji_order) x right_mean = x.loc[:, 'right'] left_mean = x.loc[:, 'left'] right_mean['男'] left_mean['女']fig, ax = plt.subplots() plt.plot(right_mean['男'], label = "男生, 右眼") plt.plot(right_mean['女'], label = "女生, 右眼", linestyle = '--') plt.plot(left_mean['男'], label = "男生, 左眼") plt.plot(left_mean['女'], label = "女生, 左眼", linestyle = '--') plt.legend(loc='best') plt.xticks(rotation=45)

?

?可以看出,視力的頂峰是一年級時期。或者大班時期,這時候,視力發育成熟,基本都是5.0.從小學開始,一路下降。

總結

以上是生活随笔為你收集整理的儿童视力数据(2)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。