微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 `plm` 包中为 `pcce` 模型扩展 `texreg` 时出错

如何解决从 `plm` 包中为 `pcce` 模型扩展 `texreg` 时出错

您好 stackoverflow 社区,我正在尝试将 signals.py 扩展到其他模型,但最终出现错误validobject(.Object) 中的错误:无效类“texreg”对象:无效对象类“texreg”中的插槽“coef.names”:得到类“NULL”,应该是或扩展类“字符”。我不明白错误消息以及如何解决它。希望能帮到你。

以下是所用包和数据的表示、我编写的扩展代码、模型公式和我拟合的 import ffmpeg import os import shutil import subprocess def lossless_trim_and_crop(path,output_path,start,end,x,y,width,height,fps): # Trim the video in time and export all individual jpeg with ffmpeg + mjpeg2jpeg jpeg_folder = os.path.splitext(output_path)[0] jpeg_path = os.path.join(jpeg_folder,"frame_%03d.jpg") stream = ffmpeg.input(path,ss=start/fps,t=(end-start)/fps) stream = ffmpeg.output(stream,jpeg_path,vcodec='copy',**{'bsf:v': 'mjpeg2jpeg'}) stream.run(quiet=True) # Crop all individual jpeg with jpegtran for filename in os.listdir(jpeg_folder): filepath = os.path.join(jpeg_folder,filename) out_filepath = os.path.splitext(filepath)[0] + "_c.jpg" subprocess.call( "jpegtran -perfect -crop {}x{}+{}+{} -outfile {} {}".format( width,out_filepath,filepath),shell=True) os.remove(filepath) # Join individual jpg back together cropped_jpeg_path = os.path.join(jpeg_folder,"frame_%03d_c.jpg") stream = ffmpeg.input(cropped_jpeg_path,framerate=fps) stream = ffmpeg.output(stream,vcodec='copy') stream.run(quiet=True) # Delete jpeg directory shutil.rmtree(jpeg_folder) 模型以及我为 texreg 编写的代码

pcce

reprex package (v2.0.0) 于 2021 年 4 月 28 日创建

texreglibrary(reprex) library(plm) library(texreg) #> Version: 1.37.5 #> Date: 2020-06-17 #> Author: Philip Leifeld (University of Essex) #> #> Consider submitting praise using the praise or praise_interactive functions. #> Please cite the JSS article in your publications -- see citation("texreg"). AT <- structure(list(country = c("Hong Kong","Hong Kong","South Korea","Singapore","Singapore"),ccode = structure(c(1L,1L,2L,3L,3L),.Label = c("1","2","3"),class = "factor"),year = structure(c(1L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L,32L,33L,33L),.Label = c("1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017"),rgg = c(0.7,11.1,13.4,8.5,2.3,3.8,5.7,6.2,6,2.4,4.3,5.1,-5.9,2.5,7.7,0.6,1.7,3.1,8.7,7.4,7,6.5,2.1,-2.5,6.8,4.8,2.8,2.2,11.2,12.5,11.9,9.8,10.4,9.2,9.6,7.6,5.9,-5.5,11.3,8.4,4.9,5.2,5.3,5.8,3,0.8,3.7,3.2,2.9,-0.6,1.3,10.8,10.2,6.7,6.6,11.5,7.2,7.5,8.3,-2.2,9,-1.1,3.9,4.5,1.9,0.1,14.5,6.3,4.4,3.7),hdi = c(NA,NA,0.781,0.786,0.791,0.799,0.804,0.808,0.811,0.816,0.817,0.821,0.827,0.835,0.842,0.851,0.862,0.871,0.883,0.887,0.896,0.898,0.901,0.904,0.911,0.915,0.923,0.927,0.93,0.933,0.728,0.739,0.746,0.756,0.767,0.778,0.789,0.797,0.824,0.832,0.839,0.847,0.855,0.869,0.874,0.884,0.888,0.89,0.893,0.9,0.903,0.718,0.729,0.74,0.751,0.763,0.773,0.782,0.793,0.798,0.809,0.819,0.822,0.83,0.838,0.845,0.868,0.878,0.909,0.914,0.92,0.928,0.929,0.932),ineq = c(38.5,38.5,38.7,38.8,39,39.1,39.2,39.4,39.5,39.7,39.8,39.9,40,40.1,40.2,40.3,40.4,40.5,40.6,40.7,40.8,40.9,41,30.6,30.5,30.3,30.1,29.9,29.5,29.1,28.8,28.9,30.8,30.7,30.9,31.3,31.4,31.5,31.2,31,31.1,31.7,32.3,32.7,37.1,37.2,37.3,37.4,37.6,37.8,38,38.2,38.3,38.4,38.6,38.9,39.3,38.6),emp = c(96.5779467680608,97.037037037037,98.1684981684982,98.9130434782609,98.9090909090909,98.5454545454545,98.2142857142857,98.2078853046595,97.9020979020979,97.9522184300341,97,97.1518987341772,97.8328173374613,95.1219512195122,93.6746987951807,95.0536423448521,94.9114463280133,92.679836433796,92.0595533498759,93.1877704395354,94.4089185671439,95.2124979002184,95.9859757612567,96.4780600461894,94.7354042018414,95.6709718282709,96.5785423023953,96.7161969224261,96.5993100049285,96.703779287541,96.6847714695634,96.6072294074131,96.8732579942229,96.0107747562853,96.2087366592206,96.92407989095,97.4861303744799,97.4310603118238,97.5511084740277,97.7086058069579,97.6101338530181,97.2282307963177,97.5926652284762,97.9811058360907,97.9946335263381,97.4332933247161,93.1860551826995,93.7459554405103,95.5848494424631,96.0152814179734,96.7365764511357,96.4370958642538,96.3387699626232,96.2602243022177,96.5201465201465,96.7557800501006,96.839232617816,96.3631925799365,96.3014906234974,96.6048288628934,96.7960901439044,96.901332924774,96.5009688478164,96.4092365484477,96.3199358085929,96.3132478016434,95.8850931677019,93.5334872979215,95.3348382242287,96.7343976777939,97.8245614035088,98.3365323096609,98.0694980694981,97.2839506172839,97.3105134474328,97.4010632014176,97.3127501429388,97.0033296337403,97.5479744136461,96.7908902691511,95.4453441295547,95.5748175182482,96.5566037735849,95.8028096182022,95.4936643169139,95.5677014390025,95.7544778641433,96.5961219690837,97.1073312917389,97.2175924351168,95.9042904290429,97.1714659268471,97.300052516141,97.4091260634184,97.3633011005604,97.4340092896794,97.3799368526007,97.201045523851,97.076838939021),total = c(15.9202011096209,15.2642825978261,13.8835753131415,14.171521799986,15.5469757911512,16.2006058337021,15.9486863729186,15.6059692740854,17.0032284957751,16.1152020882272,17.4536584742895,17.4451762082705,17.4616562021679,20.8186896901981,21.6256036670214,20.6063397335778,20.4113562357415,20.5390063213912,21.9111794752636,19.9850563689254,17.8123041515447,16.2881456160271,15.2956584740567,19.3831636785522,18.5139928099829,18.0467390105003,19.9356916507705,19.6449391009293,21.3882491038463,18.7657106953303,19.515152525977,19.8665196131373,19.2677668365412,18.2838941361669,16.7893360882124,16.3493048436123,15.8058314157684,17.3263966207143,18.6222923203409,18.6186845010184,18.3122914122914,17.6746775640818,18.5912487979543,17.3210812243275,18.3435250036441,20.4010801366055,23.716320068772,24.4802421159041,19.4569224706369,20.2065482327053,16.700663008306,18.7523959085942,18.529429377332,19.1724499236407,19.942014804075,18.7129529003629,20.4577737365564,22.3441750459224,18.9894052008633,19.4864821822038,20.0737248521191,19.7596765659499,19.7692934080367,20.2798469789636,20.194744929226,20.1219895514415,27.1840918725192,29.2487692602775,35.2956131835622,23.0338268873143,22.3296755684575,21.2650165583954,21.3984158256604,19.5236899256874,17.3444918988687,13.9627690399078,16.1672524244994,21.0982307785774,16.7726977165494,20.0459861341301,19.0335889849647,19.1001660112035,22.2476498614084,18.859896102842,18.630695181316,17.1356363728505,14.7367573960416,14.7642415560525,13.8119800114872,16.6962801905864,17.9157516410459,14.505162068252,14.6621876204514,14.2683860818447,13.9857107463955,14.6498327225184,17.4691299276575,16.3177514024186,16.1987329487883),hea = c(1.35331237219938,1.39012296139184,1.28880456193846,1.24068339281965,1.37626166805798,1.57074299717504,1.57889219147519,1.72319886164745,2.02200022129493,1.87633585265879,2.21525309163951,2.0779982244978,2.08114858100801,2.45341250927843,2.55943582311373,2.44635331113771,2.58730704193796,2.55669095480679,2.72155993344309,2.4449693951702,2.23889528193326,2.13702588417475,2.03682433987821,2.14970889968708,2.31352211397352,2.24563876572623,2.34162001209659,2.92441210588402,3.16147602891075,2.54459614027403,2.93643778040929,2.66888504972291,2.67698064963211,0.236004525777253,0.244882039172693,0.360438137376572,0.327146663437084,0.320654264256361,0.318014284356002,0.330791507128968,0.172120472120472,0.157947653488146,0.113293775335722,0.135709553464953,0.162971140726297,0.171440799865865,0.215430038684241,0.218003745256285,0.144252666832813,0.118242547996786,0.0634604040847602,0.183671397777552,0.172493657253012,0.21954199487429,0.217034282466762,0.182249475570458,0.189652461215032,0.234040352007972,0.224707003842097,0.190145385982894,0.181722052891186,0.203688772351045,0.193738819469011,0.285099025319592,0.246498752627846,0.242142199627368,1.75729315195191,1.18662489610639,1.26658346045394,1.19269006536255,1.04369737883831,0.974814792664967,1.33220752415799,1.1868354829337,1.03829384670371,1.01992469246953,1.23231903781605,1.16968868285825,1.12679317908881,1.43560774061019,1.27016256195849,0.978438835207565,1.22710279451947,1.05393723556448,1.47056629854858,0.98600967942016,0.857428757968938,0.847036325559884,0.834413768201352,1.02705000412387,1.38266371458401,1.17911249217105,1.15633305279144,1.3051547956642,1.53992474358164,1.77338945762091,2.1104556658128,2.23389203660304,2.18195591534874),edu = c(2.65312254934295,2.74330336527591,2.45103241554434,2.55310028693401,2.54534416027927,2.81984956264252,2.87325008453341,2.80291513283518,2.78634413113806,2.80692929412599,3.06860671207548,3.13049941160683,3.49761183328796,3.7878657655194,4.03704577517346,3.90369801592672,4.01554110004829,4.28530355550314,4.55895705233439,4.13463239654687,3.84279012127113,3.4545492037455,3.26062725199848,4.39212714357415,3.51003016432172,3.41822362035926,3.509612650755,3.76032309324374,3.57254928553223,3.26211667673302,3.29269309671931,3.3097482919481,3.32610166994678,3.02821231798505,2.85941683708967,2.80014029029299,2.79747486980744,2.97050547581935,3.15933712534327,2.59053812508371,2.64220594220594,3.47574928737968,3.3925363396587,3.38288061481383,3.44946819314709,3.58474748276988,3.76492853879789,3.66430240458711,2.97298607931073,3.24234927575732,2.7490588299609,2.87150764600861,2.81581860404086,2.87127924885304,2.8407475525842,2.79010832918372,3.100804745037,3.22678676036798,2.84860736095385,2.95103335125591,3.13121609897679,3.2157773045399,3.21895640934146,3.03928709200442,3.08758213848554,3.17007447084711,5.86792040797975,5.30912345757944,5.09406924605926,4.37646634181556,4.03347323077971,4.22818440744866,4.89861016176806,4.34844701838364,4.29210949704791,3.16083934238965,3.05389840681155,3.1391644992948,3.15728013589295,3.64737738976167,3.80613781408793,4.01584779220318,4.32510990329825,4.40852687222882,4.0866328879784,3.70111677990171,3.18494067694719,2.94340792680498,2.87517282280681,3.11361852631013,3.28434196157492,3.04906516325946,3.05526001613958,2.90699840616009,3.0711239520434,2.9243668158173,2.86309338115704,2.88010695969337,2.79654316073746),soc = c(0.923462544798927,0.818787201314646,0.739528948274389,0.760856253061796,0.829285876906731,0.903475034886491,0.93643825664787,0.922384019592604,1.00459132195235,1.06314692655566,1.29047500462936,1.48159464871895,1.61467142068773,2.06094464195023,2.21613405941897,2.07304517903164,2.24169695611827,2.45270904103085,2.65248844365541,2.52743272518526,2.35545720102682,2.23101591045604,2.11224432926489,2.29858265392357,2.43592718374924,2.28104881294713,2.24076342902043,2.25295389087896,2.58859236638365,2.57039254337933,2.70581416681955,2.73621543797073,2.66254989227665,0.958038173947265,1.02011342792688,1.01881328800878,1.13880646723992,1.38093213762762,1.50517066841166,1.58800245714998,1.6958485958486,1.64931512773111,1.83412851298828,1.68588843248973,1.88401329576872,2.12484225946223,2.75724795045537,3.04581724475084,2.96838227079479,2.60450427731102,2.70547758860149,3.10891904963785,3.27605854084676,3.44516954344665,3.67620772244274,3.81789662502127,4.12816832890537,4.47986916970099,4.2605113278944,4.32755347038009,4.59089484327393,4.85108431789014,5.0671530867463,5.28346937106443,5.31905360104174,5.40600846043211,0.429046719847907,0.465443385972764,0.453011602644109,0.462952064844676,0.480134846382388,0.448534413802899,0.461045662284052,0.449372356090042,0.66391414508327,0.399625038594878,0.802772633775124,2.22479247830962,0.300054574632045,0.147354046546371,0.29941617470825,0.677868512532007,2.76328292742272,0.787599305999452,0.402758648123194,0.554699300098381,0.299860560049472,1.19087417959595,0.562387396236158,2.04738238467426,2.23806266575464,1.12141322262519,1.57267069626841,1.7475661167574,1.4740866149498,1.59293982998783,1.8452730832712,1.44852649425049,0.998468881705865),hou = c(3.33948975029866,2.96559565096926,2.84499918462857,3.14730736930506,3.37956287470593,3.52217419420714,3.19838995226262,2.86913368692019,3.03009720543947,3.19254826063608,3.16976856830888,3.52614736668249,3.32350101818755,4.62249482361214,5.31283152534158,4.56164144924004,3.79769926321319,3.26837354249962,3.42444987502676,2.66631433715353,2.26594671151633,2.10343426119383,1.99672150214811,3.92248960021365,2.56354546796887,2.58876156033895,3.16615230326246,2.46512251240637,3.32291230671022,2.5053484394946,2.56934136130894,2.51069677918242,2.62512011538593,0.883633412042503,0.825936623727098,0.964315904962319,0.767152113358363,1.49564431128835,1.98208023624557,1.81002350919815,1.41599511599512,1.19907602604713,1.32616177139023,1.50801643036968,1.69121987005322,1.47298776021673,1.65077514756946,2.17322224615946,1.03938650261558,1.72545013848946,0.316410006711766,1.03813749081942,1.28759304970547,1.43591117970087,1.45231485832111,1.31636449601445,1.21840226681909,1.40747769295117,0.932246755509102,0.918544049363787,1.10019266565073,0.846537733961408,0.861459532804083,0.864102757722402,0.819862548940716,1.64150076521293,1.13042249540766,4.18899047375487,3.42763370776129,2.72082421160833,2.12655469195604,1.30074980002841,1.08292120676022,1.30625772551105,1.2122266259268,0.921641040286098,1.31553839985138,1.58880790189688,1.51580510996471,2.42550596419151,2.56424941874838,2.05009251732084,2.33386271047674,2.02860723018699,2.69562385325663,2.26672057587372,1.7742548153726,1.56242692362989,1.68304624635412,1.22036828251638,1.21053389494906,1.31281348773162,1.25998438012031,0.998806345000793,0.773135293652596,0.90881541173672,0.801687873322594,1.01291891058634,1.17931417456033),eco = c(3.0019861773781,2.99744268330356,2.75233157402925,2.75233571278606,3.48448053426425,2.96041659575916,3.00732229157161,3.2050285662293,3.93357208353555,3.30150431211539,3.29282298134663,2.85294299812127,2.92916716869486,3.61136070633277,2.92889849727236,3.68126827568727,3.39123273652643,3.76770640872369,4.18813545969543,4.08618708849014,3.56569000619634,2.94601859445998,2.53520205287759,3.27738952038873,4.05497681174269,3.80418750548884,5.23590928593953,4.78223752969354,5.27123118544829,4.2708755069126,4.26042830695332,4.8497552698977,4.17898197771275,3.99805686737505,3.04178701692986,2.88863109048724,3.06883553348674,3.27543742450927,3.79704357455662,3.84867281569989,3.43015873015873,3.51171364014746,4.18073820294551,4.68429839671393,5.24874605416281,5.3683407019123,6.8063109996917,6.73385893972789,4.90366991061245,5.91116561834841,3.77500202933119,3.5697694553749,3.42378444259121,3.57408518772512,3.59770744176495,3.45100243176726,3.81055027371381,4.51579241408931,3.59947050198879,3.49519042329632,3.38883505817675,3.25882046677045,3.04185302351246,3.35158723016918,3.17265896268545,2.54197558182494,4.80686474751757,5.81037018093472,5.50778902602505,3.68399990584026,4.45571947866209,3.57182904858375,2.29718681731066,2.25301756615007,1.99386356670375,1.24616253334458,1.66186544185699,3.05918578593697,2.87981790570379,3.86986741053713,2.45767755995392,3.83258867141576,3.36105165208413,2.31840826307085,1.98706697229916,2.07337454376396,1.70671433778957,1.57065478159801,1.35451921116094,2.07798489206458,2.92208181829091,2.12835853953842,2.26329458198055,1.92392346808525,1.60523405190318,1.71887106060716,3.74753125619179,2.66953165811053,2.85793126766109),gen = c(2.28886787889448,1.97515294537279,1.71279770764145,1.61815907341312,1.74186081809213,2.06817330928151,2.15460533601478,2.02522623619552,2.32896476699945,2.03209833623527,2.42232019141392,2.36496892871152,2.24811943957291,2.32027190686409,2.49427429152884,1.94085836197506,2.29225927265956,2.12180143848071,2.247608558817,2.18611350933104,1.78787288660706,1.74503492531019,1.65875514006916,1.70338046497572,1.8374019508873,1.87493103766638,1.81211002724317,1.79390974930034,1.82097502461061,1.89088077238767,1.95298297112931,2.05829438515953,2.06754421204495,1.72262396694215,1.68391979928739,1.53114264645048,1.42659258810706,1.53552366107276,1.57938891592141,1.64559768325859,1.78962148962149,1.68863086808146,1.77652308082385,1.84245395521399,1.87510006475833,1.9940389519851,2.33471432397095,2.12126924415425,1.02097126855181,0.970409236609986,1.04926298641348,1.10262549784144,0.890868645914883,0.87451242772713,0.923218591062165,1.05479671552655,1.00735000755924,1.27589740288217,1.02161542258224,1.02942019264802,1.11220562520372,1.2503172434306,1.06543554220541,1.03225509167438,1.12162389770652,0.938171644990446,3.83059077421095,3.53430087590307,5.19114316091157,2.44226830818484,2.11804166276486,2.09764594188489,2.7421494913755,2.40814336578664,2.47217870956726,2.07693755557431,2.40579610247582,4.51572120035744,2.23381805679009,2.18769695837905,2.50842606414176,2.31325007831315,2.53903745425491,2.78069481224444,2.61233734268794,2.6021842042351,2.31984775130926,2.33324730169563,2.57021891200676,2.85275081087314,2.23768765525435,1.86809140432887,1.63849939440485,1.76660939882566,1.88233589449823,1.09197215977324,1.04488408269238,1.00824446785133,1.12956085472994),eogdp = c(84.0797988903791,84.7357174021739,86.1164246868585,85.828478200014,84.4530242088487,83.7993941662979,84.0513136270814,84.3940307259146,82.9967715042249,83.8847979117728,82.5463415257105,82.5548237917295,82.5383437978321,79.1813103098019,78.3743963329786,79.3936602664222,79.5886437642585,79.4609936786088,78.0888205247364,80.0149436310746,82.1876958484553,83.7118543839729,84.7043415259433,80.6168363214478,81.4860071900171,81.9532609894997,80.0643083492295,80.3550608990707,78.6117508961537,81.2342893046697,80.484847474023,80.1334803868627,80.7322331634588,81.7161058638331,83.2106639117876,83.6506951563877,84.1941685842316,82.6736033792857,81.3777076796591,81.3813154989816,81.6877085877086,82.3253224359182,81.4087512020457,82.6789187756725,81.6564749963559,79.5989198633945,76.283679931228,75.5197578840959,80.5430775293631,79.7934517672947,83.2993369916939,81.2476040914058,81.470570622668,80.8275500763593,80.057985195925,81.2870470996371,79.5422262634436,77.6558249540776,81.0105947991367,80.5135178177962,79.9262751478809,80.2403234340501,80.2307065919633,79.7201530210364,79.805255070774,79.8780104485585,72.8159081274808,70.7512307397225,64.7043868164378,76.9661731126857,77.6703244315425,78.7349834416046,78.6015841743396,80.4763100743126,82.6555081011313,86.0372309600922,83.8327475755005,78.9017692214226,83.2273022834506,79.9540138658699,80.9664110150353,80.8998339887965,77.7523501385916,81.140103897158,81.369304818684,82.8643636271495,85.2632426039584,85.2357584439475,86.1880199885128,83.3037198094136,82.084248358954,85.494837931748,85.3378123795486,85.7316139181553,86.0142892536045,85.3501672774816,82.5308700723425,83.6822485975814,83.8012670512117),pgr = c(1.509110516,1.6213902295,1.6840910467,1.6816633881,1.5869438622,1.4360091106,1.2508510172,1.1094188819,1.078456365,1.1952400662,1.4004867984,1.652058818,1.831424167,1.8414430378,1.6301663285,1.2776218859,0.8808217054,0.5535625205,0.3413561827,0.2951317175,0.3702200047,0.4789989929,0.5561328207,0.6098892543,0.6197244432,0.6001328504,0.5764594052,0.57280062,0.5932969652,0.6452466267,0.7167856753,0.7976599816,0.8628867461,1.2532149586,1.1227597999,1.0161254853,0.9552097325,0.9565979715,1.0004015543,1.0539528739,1.0893653533,1.1041073905,1.0880762788,1.0485889347,1.0072232606,0.9680274351,0.9150179132,0.8463611921,0.7675877228,0.6877818726,0.6129743212,0.5430073031,0.4806677607,0.4272573231,0.3676520016,0.3153014652,0.3006499971,0.3349077606,0.4008131798,0.4842668548,0.5498157446,0.5678559982,0.5194159042,0.4242950221,0.315027195,0.2213209398,2.2820293047,2.0814657296,1.9548188026,1.9790627141,2.2029075379,2.5442677753,2.8845436226,3.1267852874,3.2639875453,3.2703938822,3.1771131233,3.1328857964,3.0841213228,2.8530008352,2.4061158751,1.8571323685,1.1911778884,0.6663059572,0.6028947894,1.1551422028,2.0963008677,3.1527930213,3.9267025032,4.2163984719,3.9174727146,3.2595383154,2.5489099273,1.9906218323,1.5571124019,1.3096761134,1.1965670748,1.0934355495,0.9579125335)),row.names = c("1-1985","1-1986","1-1987","1-1988","1-1989","1-1990","1-1991","1-1992","1-1993","1-1994","1-1995","1-1996","1-1997","1-1998","1-1999","1-2000","1-2001","1-2002","1-2003","1-2004","1-2005","1-2006","1-2007","1-2008","1-2009","1-2010","1-2011","1-2012","1-2013","1-2014","1-2015","1-2016","1-2017","2-1985","2-1986","2-1987","2-1988","2-1989","2-1990","2-1991","2-1992","2-1993","2-1994","2-1995","2-1996","2-1997","2-1998","2-1999","2-2000","2-2001","2-2002","2-2003","2-2004","2-2005","2-2006","2-2007","2-2008","2-2009","2-2010","2-2011","2-2012","2-2013","2-2014","2-2015","2-2016","2-2017","3-1985","3-1986","3-1987","3-1988","3-1989","3-1990","3-1991","3-1992","3-1993","3-1994","3-1995","3-1996","3-1997","3-1998","3-1999","3-2000","3-2001","3-2002","3-2003","3-2004","3-2005","3-2006","3-2007","3-2008","3-2009","3-2010","3-2011","3-2012","3-2013","3-2014","3-2015","3-2016","3-2017"),class = c("pdata.frame","data.frame"),index = structure(list(ccode = structure(c(1L,class = "factor")),row.names = c(NA,-99L),class = c("pindex","data.frame"))) HDIMF1 <- diff(hdi) ~ diff(hea) + diff(log(edu)) + diff(soc) + diff(hou) + diff(log(eco)) + diff(log(gen)) + diff(eogdp) HDIMF2 <- diff(hdi) ~ diff(log(total)) + diff(eogdp) SMHDI1 <- pcce(HDIMF1,data = AT,model="p",trend = FALSE) SMHDI2 <- pcce(HDIMF2,trend = FALSE) extract.pcce <- function(model,include.r.squared = TRUE,include.N = TRUE,...) { s <- summary(model,...) names <- rownames(s$coef) co <- s$coef[1] se <- s$coef[2] pval <- s$coef[4] gof <- numeric() gof.names <- character() gof.decimal <- logical() if (include.r.squared == TRUE) { rs <- s$r.squared gof <- c(gof,rs) gof.names <- c(gof.names,"HPY \\ R$^2$") gof.decimal <- c(gof.decimal,TRUE) } if (include.N == TRUE) { n <- nobs(model) gof <- c(gof,n) gof.names <- c(gof.names,"Num.\\ obs.") gof.decimal <- c(gof.decimal,FALSE) } tr <- createTexreg( coef.names = names,coef = co,se = se,pvalues = pval,gof.names = gof.names,gof = gof,gof.decimal = gof.decimal ) return(tr) } setMethod("extract",signature = className("pcce","plm"),deFinition = extract.pcce) MPT <- texreg(list(SMHDI1,SMHDI2),custom.model.names = c("HDI M1","HDI M2"),caption = "Estimations of the Study Models.",caption.above = TRUE,label = "table:MPT",groups = list("Independent Variables" = 2:8,"Control Variables" = 9),custom.coef.names = c("Intercept","hea","edu","soc","hou","eco","gen","total","eogdp"),stars = c(0.01,0.05,0.10),custom.note = "\n\\item Note: ***,** and * represents the significance level of 1% 5%,and 10%,respectively.\\\\\n\\item M1 refers to models with varIoUs G items and M2 refers to models with only total.\n",single.row = TRUE,digits = 4,dcolumn = TRUE,no.margin = TRUE,center = TRUE,sideways = TRUE,table = TRUE,booktabs = TRUE,threeparttable = TRUE,scaleBox = 0.7,use.packages = FALSE,float.pos = "h!") #> Error in validobject(.Object): invalid class "texreg" object: invalid object for slot "coef.names" in class "texreg": got class "NULL",should be or extend class "character" 中,残差平方和 (RSS) 和总平方和 (TSS) 上有 summary,但我无法从输出中找出它们来自pcce。希望将它们包含在 GOF statistics输出str 会话中。

感谢您的帮助。

解决方法

该错误消息意味着您尝试从摘要中提取系数名称的结果是 NULL,而不是 character 向量。原因是您尝试访问模型中不存在的插槽 s$coef。相反,您应该从 s$CoefTable 中提取相关系数、名称、SE 和 p 值。

您还应该避免将系数名称放入名为 names 的对象中,因为这也是函数的名称,如果您在本地覆盖现有函数,则很容易混淆。

RSS 和 TSS 似乎存储在 s$ssrs$tss 下的摘要中。我已将其包含在下面的方法中。

理想情况下,还可以重用其他 extract 函数中使用的参数名称。在这种情况下,请使用 include.nobs 而不是 include.N。这将统一代码和文档,尤其是当您提供多个不同类型的模型时。

这是修改后的方法:

extract.pcce <- function(model,include.r.squared = TRUE,include.sumsquares = TRUE,include.nobs = TRUE,...) {

  s <- summary(model,...)
  coefnames <- rownames(s$CoefTable)
  co <- s$CoefTable[,1]
  se <- s$CoefTable[,2]
  pval <- s$CoefTable[,4]

  gof <- numeric()
  gof.names <- character()
  gof.decimal <- logical()
  if (isTRUE(include.r.squared)) {
    rs <- s$r.squared
    gof <- c(gof,rs)
    gof.names <- c(gof.names,"HPY R$^2$")
    gof.decimal <- c(gof.decimal,TRUE)
  }
  if (isTRUE(include.sumsquares)) {
    gof <- c(gof,s$ssr,s$tss)
    gof.names <- c(gof.names,"RSS","TSS")
    gof.decimal <- c(gof.decimal,TRUE,TRUE)
  }
  if (isTRUE(include.nobs)) {
    n <- nobs(model)
    gof <- c(gof,n)
    gof.names <- c(gof.names,"Num. obs.")
    gof.decimal <- c(gof.decimal,FALSE)
  }

  tr <- createTexreg(
    coef.names = coefnames,coef = co,se = se,pvalues = pval,gof.names = gof.names,gof = gof,gof.decimal = gof.decimal
  )
  return(tr)
}

setMethod("extract",signature = className("pcce","plm"),definition = extract.pcce)

您的函数调用中也存在一些错误。您提供了九个而不是八个替换系数名称。您没有转义自定义注释中的百分比符号。 no.margin 参数在列之间创建了重叠。并且组索引指的是九个而不是八个系数行。我也为您解决了这个问题:

MPT <- texreg(list(SMHDI1,SMHDI2),custom.model.names = c("HDI M1","HDI M2"),caption = "Estimations of the Study Models.",caption.above = TRUE,label = "table:MPT",groups = list("Independent Variables" = 1:7,"Control Variables" = 8),custom.coef.names = c("hea","edu","soc","hou","eco","gen","total","eogdp"),stars = c(0.01,0.05,0.10),custom.note = "\n\\item Note: ***,** and * represents the significance level of 1\\%,5\\%,and 10\\%,respectively.\\\\\n\\item M1 refers to models with various G items and M2 refers to models with only total.\n",single.row = TRUE,digits = 4,dcolumn = TRUE,no.margin = FALSE,center = TRUE,sideways = TRUE,table = TRUE,booktabs = TRUE,threeparttable = TRUE,scalebox = 0.7,use.packages = FALSE,float.pos = "h!")
MPT

我建议在自定义笔记中使用占位符 %stars 重新插入原始星星笔记作为自定义笔记的一部分。它有更好的格式。

您可能还想考虑重新调整因变量以避免出现如此小的系数。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。