第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 R 中用 python 重寫 t 檢驗(yàn)的問題

在 R 中用 python 重寫 t 檢驗(yàn)的問題

函數(shù)式編程 2023-10-25 11:01:02
我想在 R 中重寫 python 代碼(實(shí)際上是 Jupyter Book)。它是關(guān)于計(jì)算一些數(shù)據(jù)的 t 檢驗(yàn)函數(shù),以便在使用箱線圖之后將其可視化。我是 Python 和 R 的初學(xué)者,但我做了一些嘗試。這是Python中的代碼:import mathimport numpy as npimport pandas as pdfrom myst_nb import gluefrom scipy.stats import ttest_indfrom matplotlib import pyplot as pltlabels = ['non-failing heart (NF)', 'failing heart (F)']data = [(99, 52), (96, 40), (100, 38), (105, 18),         (np.nan, 11), (np.nan, 5), (np.nan, 42),         (np.nan, 55), (np.nan, 53), (np.nan, 39),        (np.nan, 42), (np.nan, 50)]df = pd.DataFrame.from_records(data, columns=labels)tt = ttest_ind(df['non-failing heart (NF)'],                df['failing heart (F)'],                equal_var=False, nan_policy='omit')pvalue = tt.pvalueglue('pvalue', math.ceil(pvalue * 1000.0) / 1000.0)這是我嘗試過的:library(math)labels(data) <- c("non-failing heart (NF)", "failing heart (F)")library(reticulate)np <- import("numpy", convert=FALSE)(x <- np$arange(1, 9)$reshape(2L, 2L))## [[  99.   52.]##   [  96.   40.]##   [  100.   38.]##   [  105.   18.]##   [ np.nan.   11.]##   [ np.nan.  5.]##   [ np.nan.  42.]##   [ np.nan.  55.]##   [ np.nan  53.]##   [ np.nan  39.]##   [ np.nan.  42.]##   [ np.nan  50.]##   [ 23.  24.]]df = pd.DataFrame.from_records(data, columns=labels)tt = ttest_ind(df['non-failing heart (NF)'],                df['failing heart (F)'],                equal_var=False, nan_policy='omit')pvalue = tt.pvalueprint(pvalue)
查看完整描述

1 回答

?
蝴蝶刀刀

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個(gè)贊

如前所述,t.test它是 R 庫中眾多內(nèi)置統(tǒng)計(jì)方法之一stats。因此,只需構(gòu)建相同的數(shù)據(jù)框,然后運(yùn)行測(cè)試并根據(jù)需要提取測(cè)試統(tǒng)計(jì)數(shù)據(jù)。

數(shù)據(jù)構(gòu)建?(一些需要復(fù)制的爭論pd.DataFrame.from_records()

我想在 R 中重寫 python 代碼(實(shí)際上是 Jupyter Book)。它是關(guān)于計(jì)算一些數(shù)據(jù)的 t 檢驗(yàn)函數(shù),以便在使用箱線圖之后將其可視化。


我是 Python 和 R 的初學(xué)者,但我做了一些嘗試。這是Python中的代碼:


import math

import numpy as np

import pandas as pd

from myst_nb import glue

from scipy.stats import ttest_ind

from matplotlib import pyplot as plt


labels = ['non-failing heart (NF)', 'failing heart (F)']

data = [(99, 52), (96, 40), (100, 38), (105, 18),?

? ? ? ? (np.nan, 11), (np.nan, 5), (np.nan, 42),?

? ? ? ? (np.nan, 55), (np.nan, 53), (np.nan, 39),

? ? ? ? (np.nan, 42), (np.nan, 50)]


df = pd.DataFrame.from_records(data, columns=labels)

tt = ttest_ind(df['non-failing heart (NF)'],?

? ? ? ? ? ? ? ?df['failing heart (F)'],?

? ? ? ? ? ? ? ?equal_var=False, nan_policy='omit')


pvalue = tt.pvalue


glue('pvalue', math.ceil(pvalue * 1000.0) / 1000.0)

這是我嘗試過的:


library(math)


labels(data) <- c("non-failing heart (NF)", "failing heart (F)")

library(reticulate)

np <- import("numpy", convert=FALSE)

(x <- np$arange(1, 9)$reshape(2L, 2L))

## [[? 99.? ?52.]

##? ?[? 96.? ?40.]

##? ?[? 100.? ?38.]

##? ?[? 105.? ?18.]

##? ?[ np.nan.? ?11.]

##? ?[ np.nan.? 5.]

##? ?[ np.nan.? 42.]

##? ?[ np.nan.? 55.]

##? ?[ np.nan? 53.]

##? ?[ np.nan? 39.]

##? ?[ np.nan.? 42.]

##? ?[ np.nan? 50.]

##? ?[ 23.? 24.]]



df = pd.DataFrame.from_records(data, columns=labels)

tt = ttest_ind(df['non-failing heart (NF)'],?

? ? ? ? ? ? ? ?df['failing heart (F)'],?

? ? ? ? ? ? ? ?equal_var=False, nan_policy='omit')


pvalue = tt.pvalue

print(pvalue)


查看完整回答
反對(duì) 回復(fù) 2023-10-25
  • 1 回答
  • 0 關(guān)注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)